The result is 2, but I don't understand why. Whenever the sub runs, $i is way out of scope (add print $i below the } of the for loop to test) - but within the sub it still exists even if that sub runs in a complely different context?for my $i (1..3) { $numbers{$i} = sub { print $i; }; } &{$numbers{2}};
In reply to Constant value in anonymous sub by Sewi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |