Now each closure will have it's own version of $state. The reason being that closures by definition save lexical state.sub make_closures { my $j = 0; my @closures; while (++$j < 7) { my $state = $j; push (@closures, sub {print $state, "\n";}); } return @closures; } foreach my $sub (&make_closures) { &$sub; } __output__ 1 2 3 4 5 6
_________
broquaint
In reply to Re: Closure Confusion
by broquaint
in thread Closure Confusion
by Dinosaur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |