Think about Loose Coupling | |
PerlMonks |
Re: caching hashrefs in stateby Anonymous Monk |
on Apr 23, 2014 at 02:40 UTC ( [id://1083261]=note: print w/replies, xml ) | Need Help?? |
Is this good practice? not really -- if you're abstracting away a configuration singleton, don't allow direct access to the underlying hash (the state-d hash) if you're going to allow direct access, just make it our %hash Also, like the other guy said , state $cfg never gets re-initialized, the state $cfg inside sub cfg_cache has nothing to do with the my $cfg outside
The state perldoc says "variables will never be reinitialized" but it doesn't cover what happens if the variable is a reference. Sure it does, a reference is a still just a variable, it won't be reinitialized state $f, once initialized deoesn't get reinitialized , state $f = $_[0]; only executes ONCE the very first time However multiple assignments are multiple
In Section
Seekers of Perl Wisdom
|
|