Somebody (Lance?) at tonight's SLUG meeting asked a question to the
effect of "in Perl, how do I make a static variable that is private to
a function?". Of the top of my head, I couldn't remember how to do
it, but I knew I'd done it before and that it wasn't that hard.
The answer is trivial -- try something like this:
{ my $gensym; sub gensym { ++$gensym } }
print "Hey look, a unique symbol: ", $_, "\n" while (($_ = &gensym) < 10);
If you need to initialize the value, use the BEGIN construct:
BEGIN { my $gensym = 137; sub gensym2 { ++$gensym } }
print "Hey look, a unique symbol: ", $_, "\n" while (($_ = &gensym2) < 140);
That's all there is to it. IIRC, there's a discussion of why this
works somewhere in _The Perl Cookbook_.
Sorry I couldn't stay for the entire meeting; I had to get home.
Thanks for the presentation Rob!
--kevin
--
Kevin D. Clark | | Will hack Perl for
[EMAIL PROTECTED] | [EMAIL PROTECTED] | fine food, good beer,
Enterasys Networks | PGP Key Available | or fun.
Durham, N.H. (USA) | |
**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************