Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Lexical scoping like a fox

by broquaint (Abbot)
on Mar 14, 2003 at 10:49 UTC ( [id://242996]=note: print w/replies, xml ) Need Help??


in reply to Re: Lexical scoping like a fox
in thread Lexical scoping like a fox

There's a point where I have problems, thought
Sorry, it is a rather tricky to get into words, but hopefully this code will illustrate the difference between then the length and the visibility of a scope
sub foo { ## start of visible scope ## $x a lexical var only accessable in the *visible* scope my $x = "a lexical var"; ## $y changed for the *length* of the scope local $y = "a dynamic var"; print "foo(\$x): $x\n"; print "foo(\$y): $y\n"; bar($y); } ## end of visible scope sub bar { ## $x is undefined as it is being referenced outside the ## *visible* scope of foo() ## $y is still changed as the scope of foo() has not ## *exitted* yet print "bar(\$x): $x\n"; print "bar(\$y): $y\n"; } $y = "a global var"; foo(); ## now foo() has exitted $y reverts to it's original value print "main(\$y): $y\n"; __output__ foo($x): a lexical var foo($y): a dynamic var bar($x): bar($y): a dynamic var main($y): a global var

HTH

_________
broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-18 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found