in reply to Re^4: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
in thread Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
However if you have reason to believe that one or two of the matches is likely to knock out most of the input, using loop control explcitly will be more efficient. (So will using qr// to turn the list into REs up front and stop compiling them on each line.) So even though this algorithm can be cleanly expressed with loop control it may be worthwhile to use it anyways.while (defined(my $line = <INPUT>)) { print $line if not grep {line =~ /\Q$_\E/} @list; }
Another incidental note. When processing the input of files, I use while rather than foreach whenever reasonable. The reason is that foreach puts the input into list context, which slurps the file. This can potentially take a large amount of memory. By contrast while processes the file incrementally. If you ever have occasion to work with large files, the distinction will matter.
|
|---|