in reply to Re: foreach-loop-local var in sub
in thread foreach-loop-local var in sub
I get strange results from a slight variation:
Output:use strict; use warnings; my $i = 6; sub my_print { print $i; }; for ($i = 1; $i < 3; $i++) { my_print(); print " (C-Style:\$i==$i)\n"; } for $i (qw|x y|) { my_print(); print " (Perl Style:\$i==$i)\n"; }
Not that I would write code like this, but how come the "perl style" does not update the "$i" the sub sees ?1 (C-Style:$i==1) 2 (C-Style:$i==2) 3 (Perl Style:$i==x) 3 (Perl Style:$i==y)
Most people believe that if it ain't broke, don't fix it.
Engineers believe that if it ain't broke, it doesn't have enough features yet.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: foreach-loop-local var in sub
by LanX (Saint) on Jan 22, 2013 at 03:24 UTC | |
by Athanasius (Archbishop) on Jan 22, 2013 at 03:54 UTC | |
by LanX (Saint) on Jan 22, 2013 at 04:00 UTC |
In Section
Seekers of Perl Wisdom