in reply to test if a string contains a list member
Some other notes: <list>my @bad = qw(fork smurf); my $regex = join('|', @bad); $regex = qr/$regex/; foreach (<FH>){ if(/^[0000-9999](.+)/){ next if /$regex/; push( @witty_quotes, substr( $_, 5) ); } else { next }; }
use strict; my @witty_quotes; my @bad = qw(fork smurf); my $regex = join('|', @bad); $regex = qr/$regex/; # open() FH somewhere foreach (<FH>){ # Note: it's important to put this regex test # outside of the if() block to ensure that $1 # below comes from the correct pattern match next if /$regex/; if(/^\d{4}(.+)/){ push( @witty_quotes, $1); } }
-Matt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: test if a string contains a list member
by mull (Monk) on Oct 21, 2001 at 02:05 UTC | |
by demerphq (Chancellor) on Oct 21, 2001 at 17:41 UTC | |
by tilly (Archbishop) on Oct 21, 2001 at 19:32 UTC | |
by demerphq (Chancellor) on Oct 21, 2001 at 20:55 UTC | |
by mojotoad (Monsignor) on Nov 07, 2002 at 16:52 UTC |