--- loncom/localize/localize/checksimilar_2files.pl 2013/01/22 17:18:05 1.5 +++ loncom/localize/localize/checksimilar_2files.pl 2013/09/25 13:22:42 1.7 @@ -1,6 +1,6 @@ #!/usr/bin/perl # The LearningOnline Network with CAPA -# $Id: checksimilar_2files.pl,v 1.5 2013/01/22 17:18:05 bisitz Exp $ +# $Id: checksimilar_2files.pl,v 1.7 2013/09/25 13:22:42 bisitz Exp $ use strict; use warnings; @@ -20,7 +20,7 @@ use open ':utf8'; sub read { # Read file into memory my $file = shift; - open(IN,$file) or die; + open(IN,$file) or die "Error: Could not open file: $file\n"; my %filecontent = (); my $contents = join('',); close(IN); @@ -28,9 +28,8 @@ sub read { my %Lexicon = (); eval($contents.'; %filecontent=%Lexicon;'); if ($@ ne "") { - print "\nAn error occurred during the attempt to retrieve the translation hash.\n" + die "\nAn error occurred during the attempt to retrieve the translation hash.\n" ."Error: ".$@."\n"; - die; } return %filecontent; } @@ -38,7 +37,7 @@ sub read { sub similar_chars { my $text = shift; $text =~ s/\[_\d\]//g; # translation parameters - $text =~ s/[.,\_\-?!: \/]//g; # punctuation + $text =~ s/[.,\_\-?!: \/\(\)]//g; # punctuation return $text; } @@ -62,8 +61,8 @@ sub similar_phrases { ); foreach my $word (keys %phrases) { - $text1 =~ s/$phrase/X$phrases{$word}X/gi; - $text2 =~ s/$phrase/X$phrases{$word}X/gi; + $text1 =~ s/$word/X$phrases{$word}X/gi; + $text2 =~ s/$word/X$phrases{$word}X/gi; } if (lc($text1) eq lc($text2)) { @@ -77,6 +76,10 @@ sub similar_phrases { ####--------Main Program--------#### +if (!$ARGV[0] or !$ARGV[1]) { + die 'Error: Invalid files! Please specify two files which should be checked.'."\n"; +} + my $file1 = $ARGV[0]; # Old language.pm my $file2 = $ARGV[1]; # New Phrases