Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Re: regex "o" modifier

by bart (Canon)
on May 07, 2003 at 09:59 UTC ( #256155=note: print w/replies, xml ) Need Help??

in reply to Re: regex "o" modifier
in thread regex "o" modifier

When Perl encounters a variable in a regex it can't be sure that the variable will never change and so it compiles it each time the regex is used.
That used to be true, long time ago, but it is no longer so. Even if your regexp contains variables and you don't use /o, perl may still not compile it again... simply because these days, perl contains a check to see if the scalar has changed since last time the regexp got compiled...

Benchmarking will show you that, in case the scalar doesn't change, not using /o is comparable in speed, or might even be appear slightly faster (difference < 1%) than when using /o — but likely that's just inaccuracies in the benchmark.

/o does prevent recompiling the regexp, even if the scalar changes. Likely this is not what you want.

Therefore, use of /o in modern perl is largely obsolete.

Replies are listed 'Best First'.
Re: Re: Re: regex "o" modifier
by diotalevi (Canon) on May 15, 2003 at 00:16 UTC

    You should attribute the difference between /constant/o and /constant/ to noise. I've checked the source code, followed the execution path with gdb and verified that there is no C code difference between the two. Consider it like comparing the performance benefits between "\40", " " and "\x32".

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://256155]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2018-04-19 18:27 GMT
Find Nodes?
    Voting Booth?