|Welcome to the Monastery|
Curious about Hashes which viewed as a list has only one itemby ack (Deacon)
|on Feb 28, 2008 at 23:56 UTC||Need Help??|
ack has asked for the wisdom of the Perl Monks concerning the following question:
This regards a thread started in Meditations to which I wanted to reply (actually ask a question); but I thought it more appropriate to bring my question into this forum. The original node in Meditations involved a simple construct from some legacy code the author was trying to maintain. It included the following code snippet:
I don't believe the subsequent discussion is relevant (the reference is from this post by vrk) nor am I particularly concerned about the unlink portion (though that was what most of the rest of the thread was about).
But my question is as follows:
Since the original hash, %foo, was assigned an anonymous hash, doesn't that make it a hash with a single entry (that entry is a reference to the anonymous hash)? So %foo's entry is a single value and it resolves to the stringified version of the anonymous hash (if it is, indeed, used as a key)...doesn't it?
But, presuming that %foo (viewed as a list) only has the single entry (the author of the node says on his machine the stringified reference is HASH(0x814dc30)), then it begs...for me, at least...another question. How does a hash handle a single value...i.e., it either has no key or no value for the key. That is to say, is the HASH(0x814dc30) a key or a value?
I naively presume that it is considered the key (the stringified version of the anonomyous hash reference) and that the value associated with the key is undef (or maybe it is just empty, a null?).So, my question is how does Perl handle a hash like the above if that hash is used in a list context (which is important to understanding what unlink will do given the hash, unlink will use the hash in its list context)?