Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Re: Lexical scoping like a fox

by broquaint (Abbot)
on Mar 14, 2003 at 10:49 UTC ( #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



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://242996]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2018-07-22 15:07 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (454 votes). Check out past polls.