Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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


Comment on Re: meaning of /o in regexes

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-08-01 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (20 votes), past polls