in reply to RE (tilly) 3 (closures): for loops
in thread for loops, closures
is (roughly) equivilant, scope-wise, to:my @coderefs; for $i (@array) { push @coderefs, sub { print $i; }; }
In the second case, it is abundantly clear that the $i captured by the closure is different for each iteration, and is an alias for the underlying array element.my @coderefs; for (@array) { my $i = \$_; push @coderefs, sub { print $$i; }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (tilly) 5 (closures): for loops
by tilly (Archbishop) on Aug 21, 2000 at 01:11 UTC |