I got bit by 'exists' causing autovivication again. It seems that every year I forget about it at least once. I would have thoguht this would have been "fixed" in Perl 5.10 since Perl certainly isn't doing what I mean.

So now I'm curious -- what's the rationale behind it? Is it just something hard to code around in the Perl 5 codebase? Or something else? Would it be possible to have perl throw a warning in a future 5.10 (or 5.12) release?

Obligatory code snippets....

# Broken version: next LASTLOG unless exists $user_by_uid{$uid}->{$host}; # Data::Dumper output when $uid is not in the hash: $user_by_uid = { '93688' => {}, '58684' => {}, '58017' => {}, }; # Fixed version: next LASTLOG unless exists $user_by_uid{$uid} && exists $user_by_uid{$ +uid}->{$host};

Update: I'd like to thank everyone for the replies. I was interested in the history of why it was designed/implemented this way and perrin gave me some things to look at in 659433. I'd like to thank ikegami for his answers in the 659446 thread and special thanks to tye for his responses in Re: Why does exists cause autovivication? (myth, mods) and 659643 respectively. Again, thanks everyone!

Update2: I'd especially like to thank demerphq for his reply in: "Re^7: Why does exists cause autovivication?"!

Happy Holidays!


In reply to Why does exists cause autovivication? by Argel

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.