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

Re: declaring a common loop variable

by AnomalousMonk (Archbishop)
on Feb 28, 2017 at 22:24 UTC ( [id://1183206]=note: print w/replies, xml ) Need Help??


in reply to declaring a common loop variable

Further to 1nickt's post: pritesh_ugrankar: Note that the local scoping (or aliasing) of a for-loop iteration variable is very strong and holds even if you do not declare a separate lexical for each loop:

c:\@Work\Perl\monks\nysus>perl -wMstrict -le "my @x = (1, 2); my @y = qw(foo bar); ;; my $z = 'original'; for $z (@x) { printf qq{$z }; for $z (@y) { printf qq{'$z' }; } print $z; } print qq{after all loops: '$z'}; " 1 'foo' 'bar' 1 2 'foo' 'bar' 2 after all loops: 'original'
(But yes, certainly use different variable names as a sanity-saver!)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found