in reply to static storage in a local subroutine?

I think you probably want a lexical variable which is in a naked block which contains the function that manipulates the variable. Something like this:

{ my $count; sub manipulate_count { ++$count; print "manipulate_count has been called $count times\n"; } }

Update: Yeah. And what merlyn said below.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: static storage in a local subroutine?
by merlyn (Sage) on Nov 23, 2005 at 14:51 UTC
    You need to make that "BEGIN {" not "{" to ensure that the initialization for $count happens once and only once. For example, if that code were in some sort of outer loop, you'd get $count cannot stay shared (I think), and if you had an initializer for $count, but that block were at the end of the file, "manipulate_count" would be called before $count had been initialized.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.