in reply to lazy creation of a hash

> So my current plan is to use a separate lexical variable to keep track of whether it's been loaded, since that is fastest to check. But it bugs me to use a separate variable, and I still wonder if there is a better (or at least "cooler") way.

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() ) {...}