exists has never had any special power over auto-vivification at all. See Re^10: searching a list (myth) for a full explanation of that.

See Data::Diver for an alternate solution. Well-considered suggestions for improvements welcome; I'm quite sure there is ample room for improvement.

Rather than "fix" exists to prevent auto-vivification, I'd prefer to have a pragma that makes auto-vivification a fatal error (or optionally a warning). There are times when I program very carefully and any case of autovivification is quite simply the indication of a bug. It is a rather like "use strict" or like the "Use of uninitialized value" warning. There are often times where the restrictions imposed by such things are inconvient (one-liners in the case of "use strict") but there are other times where enforcing "extra care" is a real boon.

I also think such a pragma would be easier to implement than changing exists. Also, once you have the pragma, it makes it easier to give that power to exists as well -- since the pragma requires a flag for "don't auto-vivify" that can be attached to op-nodes (that is how lexical pragmata work) and "fixing" exists would require the same flag.

- tye        


In reply to Re: Why does exists cause autovivication? (myth, mods) by tye
in thread 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.