You want to read the file only once and look for both strings. You don't care whether the second is found when the first is not found, but it's probably cheaper to look for both from the beginning rather than go back and reread the file when it's time to look for the second string.
What you're doing right now is looking for the second string only on lines that contain the first string.
sub edits { return if ! -f; return if ! /^Khlog.08$/; open my $log_fh, '<', $_ or die "Can't read '$File::Find::name': $!"; my ( $found1, $found2 ); while ( defined( my $line = <$log_fh> ) ) { $found1 = $found1 || ( $line =~ /002389983/ ); $found2 = $found2 || ( $line =~ /29994339499/ ); last if $found1 && $found2; } }
In reply to Re: How to search for two strings/regex in one file
by kyle
in thread How to search for two strings/regex in one file
by learningperl01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |