I've been told, but haven't been able to verify when this change took place, that the latest versions of Perl won't recompile a regular expression using interpolation if the variable hasn't changed.

I didn't find any mention of this in perl56delta, perl561delta, the Changes file for 5.6.0, or the Changes file for 5.6.1.

However, it's easy to verify whether a given version has the optimization or not. Since at least 5.6.0,

use re 'debug'; for (1..2) { $re_str = $_; print("***** $_ *****\n"); /$re_str/; } $re_str = "\\d"; for (3..4) { print("***** $_ *****\n"); /$re_str/; }

outputs

***** 1 ***** Compiling REx `1' Guessing start of match, REx "1" against "1"... ***** 2 ***** Compiling REx `2' Guessing start of match, REx "2" against "2"... ***** 3 ***** Compiling REx `\d' Matching REx "\d" against "3" ***** 4 ***** Matching REx "\d" against "4" <--- No "Compiling" before this.

(irrelevant lines omitted).

I've personally tested this with 5.6.0, 5.6.1, 5.8.0 and 5.8.8.


In reply to Re: Year end FAQ stubborn answer help, 2006 edition by ikegami
in thread Year end FAQ stubborn answer help, 2006 edition by brian_d_foy

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.