$ perl -Mre=debug -c -e'/a/'
Compiling REx "a"
Final program:
1: EXACT <a> (3)
3: END (0)
anchored "a" at 0..0 (checking anchored isall) minlen 1
-e syntax OK
Freeing REx: "a"
Each instance of a regex operator (m//, s///, qr//) that interpolates caches the last pattern it compiled in string and compiled form. If that instance is evaluated again, and if the generated pattern is the same as the previous one, recompilation is skipped.
$ perl -Mre=debug -e'$x = "a"; for my $y (qw( b b a a )) { /$x/; /$y/;
+ }' 2>&1 | grep -i comp
Compiling REx "a"
Compiling REx "b"
Compiling REx "a"
Skipping recompilation of unchanged REx "a" /$x/ same as last
Compiling REx "b"
Skipping recompilation of unchanged REx "b" /$y/ same as last
Compiling REx "a"
Skipping recompilation of unchanged REx "a" /$x/ same as last
Compiling REx "a"
Compiling REx "a"
Skipping recompilation of unchanged REx "a" /$x/ same as last
Compiling REx "a"
Skipping recompilation of unchanged REx "a" /$y/ same as last
It still needs to perform the interpolation, and it needs to perform a string comparison, so it won't be as exactly as fast as using /o. But it should be close.
|