On Sat Sep 03 07:47:42 2011, peter@peterscott.com wrote:
> perlre says:
>
> "(??{ code })"
> [...]
> The result of evaluation is considered a regular
expression and
> matched as if it were inserted instead of this construct.
Note
> that this means that the contents of capture groups defined
> inside
> an eval'ed pattern are not available outside of the
pattern, and
> vice versa, there is no way for the inner pattern to refer
to a
> capture group defined outside. Thus,
>
> ('a' x 100)=~/(??{'(.)' x 100})/
>
> will match, it will not set $1.
>
> The last assertion is true, however, the one before it appears not to be:
>
> % perl -E '"abc" =~ /(.)(??{say "\$1=$1"; "(.)"})/ and say "\$2=$2"'
> $1=a
> $2=
>
> In other words, the subexpression
It says ‘inner pattern’, not subexpression. That appears to be true:
$ perl -E '"aa" =~ /^(.)(??{say "\$1=$1"; q"(\1)"})/ ? say "\$2=$2" :
say "fail"'
$1=a
fail
> *can* access capture groups defined
> outside itself. Either the documentation or the code should be changed.
Maybe the documentation should be clarified. Do you have any suggestions?
Thread Previous
|
Thread Next