Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: RE: Re: Scope of regular expression variables

by Carl-Joseph (Scribe)
on Aug 30, 2000 at 03:47 UTC ( [id://30242]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Scope of regular expression variables
in thread Scope of regular expression variables

The behavior of the regex vars is similar to what is obtained by using "local" inside the if() conditional.

I've modified Merlyn's code to show that the value of regex vars is sustained through a function call.

sub PrintRegExVar { print "Inside called sub: $1 $2\n"; } $_ = "abcde"; if (/(.)(.)/) { # first two if (/(.)(.)$/) { # last two # # This prints "d e" # print "inner: $1 $2\n"; &PrintRegExVar; } # # This also prints "d e" # print "outer: $1 $2\n"; &PrintRegExVar; } $_ = "abcde"; if (/(.)(.)/) { # first two { # ADDED EXTRA BLOCK if (/(.)(.)$/) { # last two # # This prints "d e" # print "inner: $1 $2\n"; &PrintRegExVar; } } # ADDED EXTRA BLOCK # # This prints "a b" # print "outer: $1 $2\n"; &PrintRegExVar; } __END__ inner: d e Inside called sub: d e outer: d e Inside called sub: d e inner: d e Inside called sub: d e outer: a b Inside called sub: a b

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-16 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found