in reply to Re: Re: Re: Is there an InString-like function?
in thread Is there an InString-like function?
As was already pointed out, this if ($var =~ /^[qw(Smith Jones Schmidtz)]/) doesn't work as it just creates a character class equivalent to [SmithJonescdz] - which just compares to the first character of $var. Two solutions:
my @names = qw(Smith Jones Schmidtz); my $pattern = join '|', @names; if ($var =~ /^(?:$pattern)/) # or quicker if ($var =~ /^Smith/ || $var =~ /^Jones/ || $var =~ /^Schmidtz/)
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re4: Is there an InString-like function?
by Anonymous Monk on Jul 24, 2001 at 17:08 UTC | |
by Hofmator (Curate) on Jul 24, 2001 at 17:19 UTC |