#!/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:
Update: except for that being backwards. Try:while( $line= <IN> ) { for( @avoid ) { if( $line =~ $_ ) { print $line; last; } } }
- tye (but my friends call me "Tye")while( $line= <IN> ) { for( @avoid ) { if( $line =~ $_ ) { $line= ""; last; } } print $line; }
In reply to Re: Re: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by tye
in thread Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by quasimojo321
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |