You might want to try one more thing before you put it away.  Add 'use
strict'.  It's a bit of a pain at first, but it's a very good habit to get
into.

-----Original Message-----
From: Anthony Saffer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 8:01 AM
To: Perl Beginners List
Subject: Final Code (I think it's gonna work!)


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...";



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to