BrowserUK's solution implies that you want to do something with a file if it contains one of the words 'PASS', 'sweeps', 'Final', but from your post, I take it a file should match all three of them. The following code snippet should do that.
This is not going to win a prize for elegance or generality, but it should be along the lines you want.open(FILE, "$some_dirr/$file") or die("can't open $file"); my ($PASSmatch, $sweepsmatch, $Finalmatch); while (<FILE>) { if (/\bPASS\b/) { $PASSmatch = 1; } elsif (/\bsweeps\b/) { $sweepsmatch = 1; } elsif (/\bFinal\b) { $Finalmatch = 1; } } close(FILE); if ($PASSmatch && $sweepsmatch && $Finalmatch) { # do whatever with this file. }
Hope this helps, -gjb-
Update: graff makes two good points about the code above: 1) one shouldn't die in a directory scan when a file can't be read and 2) it would be more efficient to last out of the while as soon as the three words have been found for efficiency's sake.In reply to Re: Perl Matching Question
by gjb
in thread Perl Matching Question
by biggin777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |