Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Why is it uninitialized?

by hdb (Monsignor)
on Dec 21, 2017 at 09:03 UTC ( #1205967=note: print w/replies, xml ) Need Help??


in reply to Why is it uninitialized?

I have to admit ignorance of what really happens inside Perl but a small experiment sheds a bit of light on the situation:

use strict; use warnings; my $S4 = "aaa"; sub X { print "<$S4>\n"; return $S4; } for $S4 (1 .. 2) { print "A: <$S4> <", X(), ">\n"; }

which supports the "closure theory", imho.

Update: adding to my experiment as follows

use strict; use warnings; my $S4 = "aaa"; sub X { print "<$S4>\n"; return $S4; } for $S4 (1 .. 2) { print "A: <$S4> <", X(), ">\n"; } $S4 = "bbb"; print "B: <", X(), ">\n";

which seems to confirm the theory that the loop variable is implicitly localized.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-05-22 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?