Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: meaning of /o in regexes

by dakkar (Hermit)
on Dec 06, 2002 at 12:48 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found