On Wednesday, September 18, 2002, at 08:22 AM, Anthony Saffer wrote: > Hello Again All,
Howdy. > 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... I'm just getting into this thread, so I apologize in advance for my lack of knowledge about what has come before. > Thanks! > Anthony If this is your full source and especially now that it's running on Linux, where's your shebang line? #!/usr/bin/perl > 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"); Just FYI, you can drop all of the parenthesis in the three statements above and they will function just the same, but maybe be a touch easier to read. Choosing less cryptic filehandle names would also help a little, I think. > @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? Okay, the line above is a problem child. I believe you mean to use that pattern match on that variable, which would be done with the match operator, as you have it in the next line below. if ($litem =~ /$matchitem/) { > $PNdString =~ m/$litem/$matchitem/i; #Yes? Replace! More trouble here. First, I think you're trying a search and replace here and that uses s/PATTERN/REPLACEMENT/, not m/PATTERN/ which is just for matching. Note: you also added the i modifier here, which means this match will follow different rules that the similar one just above (ignoring case). Also, your matching text from a string that has been set to hold nothing. Finally, I'm having a hard time helping to rewrite it correctly because I can't understand the purpose clearly. It looks to me like you are saying, if we find a match, replace it with the match, which we know will be the same thing, right? Here's how I would rewrite the loops, in psuedocode where you will need to fill in a REPLACEMENT: foreach (@FH) { # defaults to sticking the value in $_ foreach $match (@MTH) { s/$match/REPLACEMENT/; # search and replace if found, on $_ print OUTFILE $_; # print out the value, changed or unchanged } } > 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"; > } I hope this helps. If I'm missing the intent, send more information and I'll take another shot at it. Good luck! James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]