in reply to Re: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
in thread Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
#!/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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by Anonymous Monk on Jul 10, 2001 at 00:31 UTC |