1. I don't know of any way to cause a hash key to be created by use of an "if" test.

Correct. There isn't. Another operator has to come into play. However, the following fools many since the operator is invisible:

if ($hash{foo}{bar})

See my reply to the OP.

2. I don't know of any way to cause a hash key's value to be "non-existant".

delete $hash{foo}; delete @hash{qw( foo bar )}; delete local $hash{foo}; # Since 5.11.0 delete local @hash{qw( foo bar )}; # Since 5.11.0

When you test a hash key, you are testing the value of the key. It can be true or false. false values are: "undef","",'',0

The string "undef" isn't false. Plain old undef is, though.

The second and third literal you posted represent the same value.

And you're missing some, most notably "0". Except for some insane situations, anything that stringifies to "" or "0" is false. The common false values are undef, the empty string, 0 and "0".

4. If a hash key value "exists" then it can have any one of the 4 values above.

Not true. Aside from the fact that you only listed three values, a hash value can be an scalar, not just false ones.

5. If a hash key value is "defined", then there only 3 possibilities.

Not true. It can be any scalar value except undef.

Update: Added lots as I found that every claim after the first had serious errors.


In reply to Re^2: Best Hash Practices? by ikegami
in thread Best Hash Practices? by DamianKaelGreen

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.