RE: Question about Error
Are you sure you know what this 'if' statement is doing? It always evaluates true. and the m/$litem/$matchitem/i shouldn't be in quotes. if($litem, /$matchitem/){ ## always true $PNdString =~ m/$litem/$matchitem/i; ## not a pattern match if it's in quotes print (OUTFILE $PNdString\n); } else{ print(OUTFILE $litem\n); } -Original Message- From: Anthony Saffer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, September 18, 2002 9:04 AM To: Perl Beginners List Subject: Question about Error Good Morning Everyone, Got another question: I wrote my first Perl script last night and it seemed to be error free on Windows. But when I uploaded it to Linux (RH 7.3) it threw an error that I don't understand. From a Google search it seems there could be a number of problems and I am not experience enough to know which. The error I am getting is: Nested quantifiers before HERE mark in then it gives my regular expression followed by the first line of the file. I THOUGHT this code was right. But obviously it isn't. Can someone tell me why line 29 would be throwing this error or WHAT the error means? The entire code is below. Thanks again for all the help. This list has been a lifesaver. Anthony CODE: my $PNdString = ; sub process_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; @fcontents = FH; foreach $matchitem (@MTH){ foreach $litem (@fcontents){ if($litem, /$matchitem/){ $PNdString =~ m/$litem/$matchitem/i; print (OUTFILE $PNdString\n); } else{ print(OUTFILE $litem\n); } } } print Done\n; } find(\process_files, @ARGV); The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about Error
Apparantly not. What the 'if' statement was SUPPOSED to do is to check if it had found a hit and, if it did, replace the string. If it didn't, it is simply supposed to write the line out to the temp file and move on. That is obviously NOT what it is doing it seems. How would YOU structure this statement? Also, what tool are you using to evaluate the code? I'm using Visual SlickEdit but it would be nice to be able to do something like what you just did. Thanks! Anthony - Original Message - From: Nikola Janceski [EMAIL PROTECTED] To: 'Anthony Saffer' [EMAIL PROTECTED]; Perl Beginners List [EMAIL PROTECTED] Sent: Wednesday, September 18, 2002 8:04 AM Subject: RE: Question about Error Are you sure you know what this 'if' statement is doing? It always evaluates true. and the m/$litem/$matchitem/i shouldn't be in quotes. if($litem, /$matchitem/){ ## always true $PNdString =~ m/$litem/$matchitem/i; ## not a pattern match if it's in quotes print (OUTFILE $PNdString\n); } else{ print(OUTFILE $litem\n); } -Original Message- From: Anthony Saffer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, September 18, 2002 9:04 AM To: Perl Beginners List Subject: Question about Error Good Morning Everyone, Got another question: I wrote my first Perl script last night and it seemed to be error free on Windows. But when I uploaded it to Linux (RH 7.3) it threw an error that I don't understand. From a Google search it seems there could be a number of problems and I am not experience enough to know which. The error I am getting is: Nested quantifiers before HERE mark in then it gives my regular expression followed by the first line of the file. I THOUGHT this code was right. But obviously it isn't. Can someone tell me why line 29 would be throwing this error or WHAT the error means? The entire code is below. Thanks again for all the help. This list has been a lifesaver. Anthony CODE: my $PNdString = ; sub process_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; @fcontents = FH; foreach $matchitem (@MTH){ foreach $litem (@fcontents){ if($litem, /$matchitem/){ $PNdString =~ m/$litem/$matchitem/i; print (OUTFILE $PNdString\n); } else{ print(OUTFILE $litem\n); } } } print Done\n; } find(\process_files, @ARGV); -- -- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about Error
Anthony Saffer wrote: Good Morning Everyone, Hello, Got another question: I wrote my first Perl script last night and it seemed to be error free on Windows. But when I uploaded it to Linux (RH 7.3) it threw an error that I don't understand. From a Google search it seems there could be a number of problems and I am not experience enough to know which. The error I am getting is: Nested quantifiers before HERE mark in then it gives my regular expression followed by the first line of the file. I THOUGHT this code was right. But obviously it isn't. Can someone tell me why line 29 would be throwing this error or WHAT the error means? The entire code is below. Thanks again for all the help. This list has been a lifesaver. Anthony CODE: my $PNdString = ; sub process_files{ It appears that you are using this sub with File::Find::find which means that you are opening these files every time find() finds a file however the files '/home/losttre/sorted.txt' and 'temp.dat' only have to be opened once so they should be opened outside of the subroutine.. 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; @fcontents = FH; foreach $matchitem (@MTH){ foreach $litem (@fcontents){ if($litem, /$matchitem/){ Do you define $matchitem as a substring of $litem or are they supposed to be exactly the same? if ( $litem eq $matchitem ) { # exactly the same if ( $litem =~ /$matchitem/ ) { # $matchitem is a substring $PNdString =~ m/$litem/$matchitem/i; I'm not sure what you are trying to do here?? print (OUTFILE $PNdString\n); } else{ print(OUTFILE $litem\n); } } } print Done\n; } find(\process_files, @ARGV); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]