@regexps = qw( foo bar baz );
@strings = qw( abc def ghi );
for $string (@strings) {
for $regexp (@regexps) {
$string =~ /$regexp/
}
}
####
>perl -Mre=debug -e"@regexps = qw( foo bar baz ); @strings = qw( abc def ghi ); for $string (@strings) { for $regexp (@regexps) { $string =~ /$regexp/ } }" 2>&1 | find "Compiling"
Compiling REx `foo'
Compiling REx `bar'
Compiling REx `baz'
Compiling REx `foo'
Compiling REx `bar'
Compiling REx `baz'
Compiling REx `foo'
Compiling REx `bar'
Compiling REx `baz'
####
@regexps = qw( foo bar baz );
@strings = qw( abc def ghi );
for $regexp (@regexps) { # All I did was reverse
for $string (@strings) { # these two lines.
$string =~ /$regexp/
}
}
####
>perl -Mre=debug -e"@regexps = qw( foo bar baz ); @strings = qw( abc def ghi ); for $regexp (@regexps) { for $string (@strings) { $string =~ /$regexp/ } }" 2>&1 | find "Compiling"
Compiling REx `foo'
Compiling REx `bar'
Compiling REx `baz'
####
@regexps = map qr/$_/, qw( foo bar baz ); # All I did was add the qr//.
@strings = qw( abc def ghi );
for $string (@strings) {
for $regexp (@regexps) {
$string =~ /$regexp/
}
}
####
>perl -Mre=debug -e"@regexps = map qr/$_/, qw( foo bar baz ); @strings = qw( abc def ghi ); for $string (@strings) { for $regexp (@regexps) { $string =~ /$regexp/ } }" 2>&1 | find "Compiling"
Compiling REx `foo'
Compiling REx `bar'
Compiling REx `baz'