in reply to Re: About "state" variables in Perl 5.10
in thread About "state" variables in Perl 5.10

Note also that with state each created anonymous sub gets its own copy of $x

Hmmm... but you can get the same result with the closure approach:

sub get_counter { my $x = 42; return sub { $x++; } } my $s = get_counter(); say &$s();
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.

Nice, that reason convince me (and the one that kyle gave below).