In addition to what others already wrote: /o caused much confusion, and these days its performance advantage is pretty small (if it exists at all), because regex compilation is cached in newer perl versions.
As far as I know it's not officially deprecated because too much legacy code uses it, but most people discourage its usage anyway.
If you want to achieve the old behavior, constructing a regex with qr is the recommended way.
| [reply] [d/l] [select] |
Probably because /o doesn't modify the semantics of the regex at all. Its only possible impact is on performance.
| [reply] [d/l] |
I just learned a tough lesson with /o:
I had a subroutine that loops through a given list of files, slurping each file and splitting it with a RE/o; and processing each chunk.
Later I had to support files of a different format. In a test, the above routine worked fine, I just had to pass it a different RE.
But when I put the two subroutine calls together, the second one failed...
My mistake was thinking that RE/o was compiled once in its narrowest scope - that the subroutine could process 1000 files with one fixed RE, and then process another 1000 files with a different RE.
I hope I explained that well; it took me a while to figure it out!
| [reply] |
for my $re (qw( a a a b b a )) {
'' =~ /$re/;
}
>perl -Dr 731397.pl 2>&1 | find "Compiling REx"
Compiling REx `a'
Compiling REx `b'
Compiling REx `a'
Notice how the regexp is only compiled whenever the interpolated variable changes. (Tested 5.6.*, 5.8.*, 5.10.0)
| [reply] [d/l] [select] |
| [reply] |
There are regexp pattern modifiers (m, s, i and x).
There are regexp quote operator (qr//) modifiers (m, s, i, x, p and o).
There are match operator (m//) modifiers (m, s, i, x, p, o, g and c).
There are substitution operator (s///) modifiers (m, s, i, x, p, o, g, c and e).
perlre discusses regexp patterns, so it only mentioned regexp pattern modifiers. perlop mentions the operator modifiers along with the operators they modify.
By the way, you should have no reason to use the 'o' modifier now that qr// exists.
Update: It used to be that only the 'm', 's', 'i' and 'x' modifiers were listed in perlop. Now I see some of the operator modifiers are there too. 'o' was surely omitted because it's obsoleted by qr//, like I previously mentioned.
perlre for 5.6.0: msix
...
perlre for 5.6.2: msix
perlre for 5.8.0: msix
...
perlre for 5.8.8: msix
perlre for 5.8.9: msixpgc
perlre for 5.10.0: msixpgc
| [reply] |