Different results.
According to what you said, the following should print "0" instead of "1":
my $x; BEGIN { $x = 0 } my $f = sub { $x }; ++$x; print $f->();
Let's say you didn't mean the above. According to what you said, the following should print "11" instead of "12":
for (1..2) { my $x = $_; print sub { $x }->(); }
In reply to Re^4: closure clarity, please
by ikegami
in thread closure clarity, please
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |