Hi there,
On Fri, 16 Feb 2024, Scott Baker wrote:
> Reading through the perlre documentation
> <https://perldoc.perl.org/perlre#Other-Modifiers> I see:
>
> o - pretend to optimize your code, but actually introduce bugs
>
> While this is clever it should probably be more clear in the official
> documentation? What exactly does /o do? I'm guessing it was a failed attempt
> to optimize certain things? If I can get clarification on what it does I will
> update the documentation to reflect that.
That's kinda scary. Any idea when that was written? Did you find out
anything about these alleged bugs? I'm guessing (hoping) that they're
more along the lines of "your code might not do what you think it does"
than "your interpreter might not do what it's supposed to do" - but it
really isn't very clear about that.
For decades I've been under the impression that
(1) what's on page 193 of the third edition of the Camel Book, and
(2) the extract below from perlfaq6
were all all I needed to know about it:
[quote]
What is "/o" really for?
(contributed by brian d foy)
The "/o" option for regular expressions (documented in perlop and
perlreref) tells Perl to compile the regular expression only once. This
is only useful when the pattern contains a variable. ...
...
...
In versions 5.6 and later, Perl won't recompile the regular expression
if the variable hasn't changed, so you probably don't need the "/o"
option. It doesn't hurt, but it doesn't help either. If you want any
version of Perl to compile the regular expression only once even if the
variable changes (thus, only using its initial value), you still need
the "/o".
[quote]
Now I feel not only a need to look over all my code to find out where I
used the /o modifier, but also dumb that I missed that in perlre.
--
73,
Ged.