Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: ?: and saving backreferences

by BUU (Prior)
on Dec 06, 2006 at 05:31 UTC ( #588034=note: print w/ replies, xml ) Need Help??


in reply to ?: and saving backreferences

I'm rather confused as to what "because the $1 backreference is lost once you exit the scope of the if/else" means to you, to me it sounds like you think $1 is cleared after you exit the scope it was declared in, which is clearly not true.

Am I missinterpreting your statements some how?

Yeah, I was missinterpreting. Consider this retracted.


Comment on Re: ?: and saving backreferences
Re^2: ?: and saving backreferences
by ikegami (Pope) on Dec 06, 2006 at 06:10 UTC

    Did you run the code the OP posted? Since at least 5.6.1, the $1 set by the regexp inside the if is no longer in scope outside the if. The following illustrates this clearly.

    'a' =~ /(.)/; { 'b' =~ /(.)/; print("$1\n"); # b } print("$1\n"); # a

    This is documented in perlvar.

      You are quite correct and I was missinterpreting his comment. Consider it retracted.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-07-04 03:06 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 (57 votes), past polls