in reply to Re: (tye)Re: Replacement for defined(%)/defined(@)?
in thread Replacement for defined(%)/defined(@)?
undef is a scalar concept. A scalar can be a number, a string, various other things, or undef which is a special =value= meaning none of the above. A hash doesn't hold a value -- it is a tree of values. Only individual hash elements can =hold= undef.
If you are asking if %hash is in the symbol table at all, it is, since compiling the name %hash in that statement does it! So use the symbol-table hash ($main::{hash}, I think) to see if that's even in the table, but it won't tell you that there is no %hash specifically, but no $hash, @hash, etc. as well. Seeing if the HV in the glob is getting into guts, but look at Devel::Peek module to do that.
Point is what you suspect: whether the hash has zero entries in the normal way, or whether the structure has not been allocated at all yet is an internal implementation detail, not visible to the language. Conceptually, the container always exists, though it may be empty. Just as a scalar =exists= but holds the value called undef, instead of 42. There is no special value for the container that fills an analogous role.
—John
|
|---|