![]() |
|
P is for Practical | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
You can declare the keys as constants as you suggest, or use the lock_keys function from Hash::Util, which comes standard in recent perls. The latter will raise an exception at runtime if an non-existant key is set.
BTW, if you do use constants, an array is more efficient unless only a sparse set of keys are ever used at once: The difficulty in making hashes "strict" is just one of the reasons why many people dislike blessed-hashref object implementations. Update: See also: non-autovivifing hash, how to avoid mis-spelling hash keys?. blokhead In reply to Re: hash, a troublemaker?
by blokhead
|
|