As I said, I don't claim that exists is a more efficacious way to induce autovivification than defined (or than anything else for that matter), but rather that it is a bad test to use, since there is the possibility of unintended autovivification happening anywhere else, and when this happens exists gives misleading results. In other words, using a slight modification of your example (s/defined/exists/):

my %hash = ( Key1 => { john => 1, pete => 2 }, Key2 => { frank => 3, howard => 4 } ); print "Exists!\n" if exists $hash{Key7}{ted}; print "Key7 exists!\n" if exists $hash{Key7};
it is the second exists that I find problematic is not the first one, because it is the second exists that gives the misleading result (yes "Key7" exists but for the wrong reason). I'd just as soon have both tests fail, by using defined instead of exists for both.

the lowliest monk


In reply to Re^5: need explanation of @foo{@bar} = (); (hash slice) by tlm
in thread need explanation of @foo{@bar} = (); (hash slice) by Anonymous Monk

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.