in reply to caching hashrefs in state
The state perldoc says "variables will never be reinitialized" but it doesn't cover what happens if the variable is a reference.
So long as you have a reference which can be accessed through a subroutine, the data referenced by it will be accessible even if it is an anonymous hash, since the garbage collector will see that existing reference.
Personally, I tend to prefer using closures to obtain the same effect, but this has a lot to do with the fact that several of the environments where I have to work still run Perl 5.8, in which the state qualifier was not available. I do not see why using the state qualifier would not be good practice.
|
|---|