I haven't seen your method in use, but I've seen the hack.
This closure idiom is useful and used in all manner of situations.
{ my $static_data; # will persist between calls and IS PRIVATE sub do_stuff { my ( $arg1, $arg2, $reset ) = @_; # first set our static data if we have not been called before # if we have been called then $static_data will be defined # static_data can not be accessed outside of this block - ie s +ub $static_data = _expensive_or_private_init() if $reset or ! def +ined $static_data; # blah } }
Besides the more obvious private variable usage it works well when you create complex data structures or expensive calls to a DB that you only want to do once
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Re: Re: Re: Package-Level Variables
by tachyon
in thread Package-Level Variables
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |