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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |