The "thing" called %hash exists. It may have nothing in it, but it never becomes something other than a hash.

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


In reply to Re: Re: (tye)Re: Replacement for defined(%)/defined(@)? by John M. Dlugosz
in thread Replacement for defined(%)/defined(@)? by Masem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.