|Keep It Simple, Stupid|
"A meditation on Hashes", or "Why i need more aspirin"by EvanK (Chaplain)
|on Jun 15, 2006 at 22:29 UTC||Need Help??|
I've been dealing with hashes and references a lot lately, and I wrote a test script to re-educate myself on the differences between hash keys existing, being defined, and containing data...I thought I'd post it cause it's interesting, albiet far from news.
So, I declare a hash, and work with four keys:
so, as we can see from the output of this, a key can be totally undeclared (not exist), can be declared but undefined (equals undef), OR be declared AND defined yet empty (equals an empty string), all in addition to actually having a populated value. and THEN we can look at which ones evaluate to being true :o
i know that this is one of those aspects of perl that scares away sooo many newcomers, and its a shame. because even though perl can confuse a 5+ year user like myself so easily, its complexity is exactly what makes it so versatile.
so while many here already understand everything said, perhaps a few newcomers will read this and walk away not so frightened by hashes and keys and values, oh my!
edit: rearranged the code to make a bit more sense, props to ikegami for pointing it out