> 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.
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() ) {...}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.