#!/usr/bin/perl -w
use strict;
my @avoid= map qr/\Q$_\E/i, qw(leroy brown);
my $log= "/home/psmith/logfile";
open( IN, "< $log" ) or die "Can't read $log: $!\n";
my $line;
while( $line= <IN> ) {
print $line unless grep $line =~ $_, @avoid;
}
If @avoid is quite large, then having grep always match
against all of them might be worth avoiding. Maybe one day
grep will be optimized for this case. (: Until then:
while( $line= <IN> ) {
for( @avoid ) {
if( $line =~ $_ ) {
print $line;
last;
}
}
}
Update: except for that being backwards. Try:
while( $line= <IN> ) {
for( @avoid ) {
if( $line =~ $_ ) {
$line= "";
last;
}
}
print $line;
}
-
tye
(but my friends call me "Tye")
|