in reply to evaluation strategy of perl
in each iteration a new variable $i is created. the old $i (from the former loop iteration) is no longer accessible via $i, but because there is a subroutine referencing it, it is not garbage collected.foreach my $i (0 .. 2) { push @d, sub { print "$i\n" }; }
|
|---|