/$re/ and print while <>
and
while( <> ) {
while( /\b(\d+\.\d+\.\d+\.\d+)\b/g ) {
if( exists $ip{$1} ) {
print;
last;
}
}
}
Hugely slower? No. A quick benchmark here shows that the regular expression appoach is about twice as slow (and we are talking about a problem dominated by disk I/O anyway). One factor depends on how many naked IPs appear on a line. If there are several and only one interests you, the direct regexp will pick it up immediately, whereas the hash approach will have to test each one.
Another consideration is that if you want to extend the approach to search for e.g. 192.168.0.* then you can no longer use the hash approach at all, since what gets matched does not correspond to any key.
Or else I completely misread the question, in which case consider my solution withdrawn.
- another intruder with the mooring in the heart of the Perl
|