Hello Everyone,

Here is the final code for my replacement script. I am about to test it out but I 
think it will work. Thanks to all who helped!!

#!/usr/bin/perl -w

use File::Find;

my $FileCount = 0;
my $LineCount = 0;

sub process_files {
   my $FinalString = "";
   my $ConvertedText = "";
   my $TotalReplacements = 0;

   open MASTER_FILE, "/home/losttre/sorted.txt" or die ("Can't open file: sorted.txt! 
Aborting!\n");
   open TEMP_FILE, "> tempfile" or die("Can't open file: TEMPFILE! Aborting!\n");
   open THIS_FILE, "< $_" or die("Can't open target file: $_! Aborting!\n");

   @MATCH_KEYS    = <MASTER_FILE>;
   @MATCH_TARGETS = <THIS_FILE>;

   foreach $matchkey (@MATCH_KEYS) {
      foreach $lineitem (@MATCH_TARGETS) {
         if($lineitem =~ m/$matchkey/i){
            $ConvertedText = lc($matchkey);
            $FinalString = s/$matchkey/$ConvertedText/;
            print TEMP_FILE "$FinalString\n";
            $LineCount++;
            $TotalReplacements++
         }
         else{
            print TEMP_FILE "$lineitem\n";
            $LineCount++;
      }
     }
      close(TEMP_FILE);
      close(THIS_FILE);
     # unlink(THIS_FILE)
      #rename(TEMP_FILE, THIS_FILE);
      $FileCount++;
   }
}

print "Process starting...\n";
print "Cycling through files. This might take some time.\n";
find(\&process_files, @ARGV);
print "DONE!\n";
print "FILES PROCESSED: $FileCount\n";
print "LINES PROCESSED: $LineCount\n";
print "REPLACEMENTS: $TotalReplacements\n";
print "Exiting...";


Reply via email to