brainbuz has asked for the wisdom of the Perl Monks concerning the following question:
my $C = shift ; my @others = grep ( !/$C/, @_ );Now consider
$passtoC = 'Vanilla';All items match vanilla and nothing is put into others.
my @list = qw / Vanilla Vanilla_Orange_Sherbert Vanilla_Fudge_Swirl / ;
My solution is:
my @others = grep ( !/^$C$/, @_ );Which produces the desired result. I'm just wondering if there is a more direct way, or if there is any possible weirdness that might result from specifying both ^ and $ in the same regexp.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a Regexp to match a string exactly
by Ratazong (Monsignor) on Jan 27, 2010 at 07:46 UTC | |
|
Re: Using a Regexp to match a string exactly
by bart (Canon) on Jan 27, 2010 at 10:13 UTC | |
by brainbuz (Novice) on Jan 28, 2010 at 03:17 UTC | |
by bart (Canon) on Jan 28, 2010 at 06:23 UTC | |
|
Re: Using a Regexp to match a string exactly
by Anonymous Monk on Jan 27, 2010 at 07:39 UTC |