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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: meaning of /o in regexes by dakkar
in thread meaning of /o in regexes by mce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found