Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: meaning of /o in regexes

by dakkar (Hermit)
on Dec 06, 2002 at 12:48 UTC ( #218055=note: print w/replies, xml ) Need Help??

in reply to meaning of /o in regexes

When you have a regexp with interpolation (as in your example), it normally gets recompiled each time it has to be executed, because the variables to be interpolated might have changed. This is slow, but is usually the right thing.

If you are sure that the variables will not change (say, because they are set outside the loop in which the regexp is used), you can say /o to tell the compiler "don't worry, just compile this regexp the first time, the variables won't change".

Now, if you do change the variables, you're cheating the compiler, breaking your promises, and so on. The compiler still trusts you, and will not recompile the regexp (hence the results of your test).

This was all before qr//. Now I think it is the best way to avoid recompiling regexps.

So, in short, yes, it is the only difference.

        dakkar - Mobilis in mobile

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2019-10-20 21:11 GMT
Find Nodes?
    Voting Booth?