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,
('a' x 100)=~/(??{'(.)' x 100})/
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Evaluating code in a regex at runtime: (??{...})
by dave_the_m (Monsignor) on Jan 28, 2013 at 01:12 UTC | |
Re: Evaluating code in a regex at runtime: (??{...})
by Athanasius (Archbishop) on Jan 28, 2013 at 02:33 UTC | |
by LanX (Saint) on Jan 28, 2013 at 07:34 UTC | |
by Athanasius (Archbishop) on Jan 28, 2013 at 08:44 UTC | |
by LanX (Saint) on Jan 28, 2013 at 09:09 UTC | |
Re: Evaluating code in a regex at runtime: (??{...})
by Kenosis (Priest) on Jan 28, 2013 at 00:15 UTC |