We don't bite newbies here... much | |
PerlMonks |
Evaluating code in a regex at runtime: (??{...})by 7stud (Deacon) |
on Jan 27, 2013 at 23:08 UTC ( [id://1015592]=perlquestion: print w/replies, xml ) | Need Help?? |
7stud has asked for the wisdom of the Perl Monks concerning the following question: Dear Monks, perlre says this: (??{ code }) This is a "postponed" regular subexpression. The code is evaluated at run time, at the moment this subexpression may match. **The result of evaluation is considered a regular expression and matched as if it were inserted instead of this construct.** Then perlre says: Note that this means that the contents of capture groups defined inside an eval'ed pattern are not available outside of the pattern... ...Thus,
will match, it will not set $1. Huh? I checked, and in fact $1 is not set. So in my opinion, the last quoted line should say: Despite the regex insertion, *confoundingly* the capture groups inside this construct are not available after the insertion. In other words, I don't see how by inserting the resulting regex instead of this construct it follows that the capture groups in the regex won't be available, which perlre seems to think is self-evident.
Back to
Seekers of Perl Wisdom
|
|