in reply to Re^2: Regex and array
in thread Regex and array

I've used the following technique successfully for this kind of situation. It compiles the regex only once, so it can be reused efficiently in a loop:
my @array = qw( ciccio paperino palla gigio pluto ); my $TestReStr = join("|", map { "(${_})" } @array); my $TestRe = qr/$TestReStr/; my $test = 'pluto'; print "It matched!\n" if $test =~ $TestRe ;

Replies are listed 'Best First'.
Re^4: Regex and array
by Deus Ex (Scribe) on May 26, 2010 at 09:50 UTC

    Nice idea, even to speed up the code!

    Thanks!