Patterns that don't interpolate are always compiled at compile time. /o is useless for these.

$ perl -Mre=debug -c -e'/a/' Compiling REx "a" Final program: 1: EXACT <a> (3) 3: END (0) anchored "a" at 0..0 (checking anchored isall) minlen 1 -e syntax OK Freeing REx: "a"

Each instance of a regex operator (m//, s///, qr//) that interpolates caches the last pattern it compiled in string and compiled form. If that instance is evaluated again, and if the generated pattern is the same as the previous one, recompilation is skipped.

$ perl -Mre=debug -e'$x = "a"; for my $y (qw( b b a a )) { /$x/; /$y/; + }' 2>&1 | grep -i comp Compiling REx "a" Compiling REx "b" Compiling REx "a" Skipping recompilation of unchanged REx "a" /$x/ same as last Compiling REx "b" Skipping recompilation of unchanged REx "b" /$y/ same as last Compiling REx "a" Skipping recompilation of unchanged REx "a" /$x/ same as last Compiling REx "a" Compiling REx "a" Skipping recompilation of unchanged REx "a" /$x/ same as last Compiling REx "a" Skipping recompilation of unchanged REx "a" /$y/ same as last

It still needs to perform the interpolation, and it needs to perform a string comparison, so it won't be as exactly as fast as using /o. But it should be close.


In reply to Re^3: Regex /o modifier: what bugs? by ikegami
in thread Regex /o modifier: what bugs? by kcott

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.