in Advanced Perl Programming it is suggested to create the matching loop on the fly with an eval. That is, if @plain contains the string version of your @regex, then it is suggested to do something like this:
# UNTESTED CODE BELOW THIS LINE ################# foreach my $re (@plain) { my $cycle = q( foreach my $i (@array) { push @match,$re if $i =~ /).$re.q(/ }) ; eval $code ; }
This way, every "matching" cycle gets compiled and used as soon as it is needed, and you have optimization since the regexp in the pattern matching is not interpolated at every cycle
Of course, you could be not so keen on using eval $scalar, but it's a matter of taste (for many definitions of taste :-)
Ciao!
--bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
In reply to Re: Efficiency: Foreach loop and multiple regexs
by bronto
in thread Efficiency: Foreach loop and multiple regexs
by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |