Anyway, since the files are big, it would be nice to exit the while loop ASAP. Granting that all three conditions need to be met to trigger further processing, there's no point in keeping track of them separately:
(or maybe something needs to be done with @keepers in that same while loop? but that might complicate things a lot; perhaps there'll be another question from biggin777 about that in a little while...)my @keepers; opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; while ($file = readdir(<DIR>)) { if ($file =~ /Somthing/ and -f $file and open(FILE, $file) { my $pass = 0; while (<FILE>) { $pass++ if (/\b(?:PASS|sweeps|Final)\b/); last if ( $pass == 3 ); } close FILE; push @keepers, $file if ( $pass == 3 ); } } # now do whatever needs to be done with @keepers.
update: Thanks to AM's very astute reply below, I see where it might be important to keep track of each different condition separately. To keep it brief, I would just set a different bit for each condition:
... my $pass = 0; while (<FILE>) { $pass |= 1 if ( /\bPASS\b/ ); $pass |= 2 if ( /\bsweep\b/ ); $pass |= 4 if ( /\bFinal\b/ ); if ( $pass == 7 ) { push @keepers, $file; last; } } ...
In reply to Re: Re: Perl Matching Question
by graff
in thread Perl Matching Question
by biggin777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |