in reply to lazy creation of a hash
if test for emptiness is not enough for you, you could flag the state of your hash by blessing it per default to a pseudo-package "EMPTY" or "Unloaded".²
DB<123> print ref \%h HASH DB<124> bless \%h, EMPTY DB<125> print ref \%h EMPTY DB<126> delete ${main::}{h} DB<127> print ref \%h HASH
but be carefull to destroy the empty hash before loading your data, unfortunately there is no "unbless" mechanism.¹
There are also tie, tied and untie, but then those pseudo-packages need to exist and to have special methods and might slow down the use of your hash.
Cheers Rolf
1) of course you can also bless it to "Loaded" if it doesn't interfere with your plans...
2) or you just use one package with a method isLoaded() and store the state in a class variable.
if (\%h->isLoaded() ) {...}
|
|---|