in reply to Re^3: closure clarity, please
in thread closure clarity, please
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 }->(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: closure clarity, please
by BrowserUk (Patriarch) on Nov 24, 2009 at 17:08 UTC |