I also think that Perl has an internal cache that avoids recompiling the same regex all over again.
The ops that compile regex patterns (qr//, m// and s///) remember the last pattern they compiled.
_ _ _
| | | | |
>perl -Mre=debug -e"for (qw( a a a a b b b a )) { qr/$_/ }" 2>&1 | fin
+d "Compiling"
Compiling REx "a"
Compiling REx "b"
Compiling REx "a"
So if you compile the same pattern many times in a row, you'll get savings.
It's useful for code that looks like
for my $pat (...) {
for my $string (...) {
... $string =~ /$pat/ ...
}
}
But not for code that looks like
for my $string (...) {
for my $pat (...) {
... $string =~ /$pat/ ...
}
}
|