Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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.


Comment on Re: Re: regex "o" modifier
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://256155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-07-28 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (186 votes), past polls