[LON-CAPA-cvs] cvs: loncom /localize/localize checksimilar_2files.pl

bisitz bisitz at source.lon-capa.org
Thu Jan 24 08:52:21 EST 2013


bisitz		Thu Jan 24 13:52:21 2013 EDT

  Modified files:              
    /loncom/localize/localize	checksimilar_2files.pl 
  Log:
  - Corrected typo in rev. 1.5
  - More robust against errors, e.g. missing or invalid file
  
  
Index: loncom/localize/localize/checksimilar_2files.pl
diff -u loncom/localize/localize/checksimilar_2files.pl:1.5 loncom/localize/localize/checksimilar_2files.pl:1.6
--- loncom/localize/localize/checksimilar_2files.pl:1.5	Tue Jan 22 17:18:05 2013
+++ loncom/localize/localize/checksimilar_2files.pl	Thu Jan 24 13:52:21 2013
@@ -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.6 2013/01/24 13:52:21 bisitz Exp $
 
 use strict;
 use warnings;
@@ -20,7 +20,7 @@
 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('',<IN>);
     close(IN);
@@ -28,9 +28,8 @@
     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;
 }
@@ -62,8 +61,8 @@
     );
 
     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 @@
 
 ####--------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
 




More information about the LON-CAPA-cvs mailing list