fix RT #121299 - Inconsistent behavior with backreferences nested inside subpattern...
authorYves Orton <yves.orton@booking.com>
Sun, 23 Feb 2014 19:53:51 +0000 (20:53 +0100)
committerYves Orton <yves.orton@booking.com>
Mon, 24 Feb 2014 10:21:45 +0000 (11:21 +0100)
commitd1b2014af5da7b0714bfc8832c3ce55eb9aaa94a
tree57f7371ab87ac6832b0d4ced0a8551f5815a74f5
parent2395827c7bba99ac465a81aaf211d6f887d2518e
fix RT #121299 - Inconsistent behavior with backreferences nested inside subpattern references

Match variables should be dynamically scoped during GOSUB and GOSTART.
The callers state should be inherited by the callee, but once the callee
returns, the callers state should be restored.

This is different from EVAL, where the callers and callees state are
expected to not be the same (although might be the same), and where
the "reasonable" match semantics differ. Currently the following two
one liners will produce different results:

$ ./perl -Ilib -le'"<ab><>>" =~/ < (?: \1 | [ab]+ ) (>) (?0)? /x and print $&;'
<ab><>>

$ ./perl -Ilib -le'$qr= qr/ < (?: \1 | [ab]+ ) (>) (??{ $qr })? /x; "<ab><>>" =~ m/$qr/ and print $&;'
<ab>

While I think reasonable people could argue that we should special case
things when we know that the return from (??{ ... }) is the same as the
currently executing pattern I think explaining the difference would be
harder than necessary.

On the contrary making GOSUB/GOSTART exactly the same as EVAL, so that
the match vars were totally independent seems to throw away an
opportunity for much more powerful semantics than can be offered by
EVAL.
pod/perlre.pod
regexec.c
t/re/re_tests