P is for Practical | |
PerlMonks |
Re^2: Strange behavior of @- and @+ in perl5.10 regexpsby demerphq (Chancellor) |
on Sep 13, 2009 at 13:00 UTC ( [id://794989]=note: print w/replies, xml ) | Need Help?? |
Oh, just to pre-empt the question, "so why does @- have 6 elements inside of (?&expr) but not outside it", which I suspect is likely to come up. The answer is that effectively the values of $4 and $5 are localized to the scope of the (?&expr) "subroutine", so once the subpattern matches and does its "return" back to the previous context they are reverted to their previous undefined value. Again this is for good reasons, try using a subroutine in a pattern that ISNT defined in a (?(DEFINE) ... ) and play around with it. In that case you very much don't want the use of a named capture as a subroutine to pollute its use as a named capture.
--- $world=~s/war/peace/g
In Section
Seekers of Perl Wisdom
|
|