in reply to Dynamic regexp from array values
If you need only exact matches, then you should probably write it asmy $regex = join '|', @all_the_different_values; if ( $data =~ /$regex/ ) . . .
On the other hand, unless you're using the power of regexes to do something like "wildcard" matching, there's another way to do it you should consider: Make a "set" of the values, and test for the existence of $data in that set.if ( $data =~ /^($regex)$/ ) . . .
my %set; @set{ @all_the_different_values } = (); # make the set if ( exists $set{ $data } ) . . .
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (2): Dynamic regexp from array values
by VSarkiss (Monsignor) on Feb 11, 2003 at 18:16 UTC | |
|
Re: Re: Dynamic regexp from array values
by tachyon (Chancellor) on Feb 11, 2003 at 18:59 UTC |