Hello Again All,
Perhaps if you all saw my logic during this script it would help you understand what I
am trying to do and maybe see a bit better what is failing. Here is my code again, but
fully commented...
Thanks!
Anthony
my $PNdString = ""; # Setting it to blank
sub process_files{
# First, I am opening all of my files
open(FH, "< $_") or die("Error! Couldn't open $_ for reading!! Program aborting.\n");
open(MTH, "< /home/losttre/sorted.txt") or die("Error! Couldn't open $MTH for
reading!\n");
open(OUTFILE, "> temp.dat") or die ("Couldn't open temp file! Aborting\n");
@MTH = <MTH>; #Assign the contents of sorted.txt to an array
@fcontents = <FH>; #Assign the contents of the $_ to an array (a dynamic filename)
# The two foreach loops below are for matching. I am wanting to pattern match
# every single element in FH to every single line in MTH. So if my MTH file has
# 3000 lines and my FH files 5000 every line in FH will be evaluated 3000
times.
foreach $matchitem (@MTH){
foreach $litem (@fcontents){
if($litem, /$matchitem/){ # is there a match in this line?
$PNdString =~ m/$litem/$matchitem/i; #Yes? Replace!
print (OUTFILE "$PNdString\n"); # Write the replace to our temp file
}
else{ # No match?
print(OUTFILE "$litem\n"); # Write the unaltered line to temp
}
}
}
print "Done\n";
}