in reply to Re^3: static storage in a local subroutine?
in thread static storage in a local subroutine?

I'm with you now. When I first looked at your code, I was thinking it was a chunk to be embedded in a subroutine, a la
sub test{ { my $cnt = 1; sub get_count { return $cnt++; } } print get_count(); } print "test 4: ".test(4)."\n"; print "test 7: ".test(7)."\n";
so I was seeing get_count() should be defined repeatedly.
  • As you point out, since it is named, it is defined only once.
  • *Your* code shows the much more obvious and clear way of doing it -- define get_count() in a block outside any code.

  • Your explanations and examples were very helpful. Thanks a bunch!