Hmmm... but you can get the same result with the closure approach:
However, that difference is not why we introduced state variables. The big win is the psychological one of not having to look outside of the sub to find the definition of $x.sub get_counter { my $x = 42; return sub { $x++; } } my $s = get_counter(); say &$s();
Nice, that reason convince me (and the one that kyle gave below).
Thanks
citromatikIn reply to Re^2: About "state" variables in Perl 5.10
by citromatik
in thread About "state" variables in Perl 5.10
by citromatik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |