I would advise against this type of technique. Hashes are very powerful data structures, and so it's tempting to use them for a lot of varying purposes. But as you stated, this introduces risk in the misspelling of keys.
Based off the usage that you described, it sounds like what you actually want are classes. There are lots of cpan modules that make the defining and accessing of class fields very easy. This is one good one:
Class::Accessor
Another typical usage of hashes are named parameters for subroutines. There are also lots of validation techniques for this as well. But here is another module that I find effective:
Params::Validate
Ultimately, your concern about the misnaming of hash keys is alleviated when you recognize that very rarely should you ever be explicitly naming the keys. Algorithms rarely explicitly name the keys. And any other uses have their risk reduced when you put the values in scalars as soon as possible. To remove the final smidge of risk, simply have test scripts for all your core libraries anyway.
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.