in reply to avoiding hash key typos
What I do is treat hashkeys like radioactive waste: I handle them directly as little as possible. If I can programmatically generate them in one way or another, I do. If not, I limit my "direct contact" with them (i.e. cases where I actually type out a hash key) to a single initial typing of the key (usually as one in a list of arguments to qw). (Typing each key once is usually OK; it's when one has to type the same key more than once that troubles begin.)
For fields of hashref-based objects, I avoid accessing the hash slot directly, and define accessors instead. A mistyped hashkey won't trigger an error from Perl, but a mistyped accessor will.
If a program's design is such that multiple typing of the same key is unavoidable, I begin thinking about how to restructure the code.
the lowliest monk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: avoiding hash key typos
by DrWhy (Chaplain) on Apr 15, 2005 at 14:02 UTC | |
Re^2: avoiding hash key typos
by Mabooka-Mabooka (Sexton) on Apr 17, 2005 at 21:49 UTC |