Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
... the largely obsolete /o ...
The bottom line is that using /o is almost never a good idea.
Then what about something like benchmark below (this is 5.42, and I _do_ see a small but noticeable performance bump with real code which does some heavy lifting when parsing. I don't think any variables have changed; just wanted to split pieces of a regex into separate variables for clarity):
use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; my $pat = qr/\d+/; my $s = '123abc' x 1e6; cmpthese -1, { foo => sub { 1 while $s =~ /\G $pat \D+ /cgx }, bar => sub { 1 while $s =~ /\G $pat \D+ /cgxo }, }; __END__ Rate foo bar foo 1213522/s -- -88% bar 10345112/s 752% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Are perlfaq6 and perlop correct about "/o" modifier?
by choroba (Cardinal) on May 09, 2026 at 13:14 UTC | |
by Anonymous Monk on May 09, 2026 at 15:49 UTC |