Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Strange behavior of @- and @+ in perl5.10 regexps

by demerphq (Chancellor)
on Sep 13, 2009 at 13:00 UTC ( #794989=note: print w/ replies, xml ) Need Help??


in reply to Re: Strange behavior of @- and @+ in perl5.10 regexps
in thread Strange behavior of @- and @+ in perl5.10 regexps

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


Comment on Re^2: Strange behavior of @- and @+ in perl5.10 regexps

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794989]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (24)
As of 2015-07-31 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls