Anyways, in addition to the other suggestions that you have been offered, I tend to use lazy memoization as follows:
And now the initialization happens when the subroutine is called. (This is a very handy pattern when the variable takes some work to create - eg for a database handle - and you may or may not need it.){ my $foo; sub up { unless (defined)($foo)) { $foo = 1; } $foo++; } sub get { $foo; } }
In reply to Re (tilly) 1: Why no stay shared warning?
by tilly
in thread Why no stay shared warning?
by tenya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |