Personally, I want it to complain about any use of an undefined value.

That's so wrong. Paradoxically, making the use of undefined values always warn will have a net *drop* in useful warnings.

People use undefined values because they know warnings will occur if it's misused. If using undefined values always warns, a different value that never warns will be used instead.

It's true that having more warnings may turn people off and cause them to turn warnings off. Someone in my office did that right now, and I think it was for no warnings 'uninitialized'.

Nevertheless, I don't often use uninitialized values as actual values, and when I do, I check for it being !defined before using it further. So I want more restrictions on the use of uninitialized values. I would prefer if all arithmetic on undef values threw a warning, for example, or use in a boolean context.

Not to mention it's silly to have defined($undef), my $x = undef; and my $x = 123; warn.

Thank you for pointing out defined(): since it's defined to deal with undef, certainly it should not throw a warning with undef! Similarly with //, and exists is arguably in the same class.

However, "my $x = undef" is equivalent to "my $x" or even "undef my $x". And I don't consider "my $x = 123;" to use undef at all: in this context, you can't tell that $x was ever assigned undef, and even if it was, that value is never referenced but is instead stomped out of existence.

In C, the term I'm looking for is "rvalue": I would like warnings whenever I try to access the value of undef.

Thank you for the pointer to "no autovivification;" I don't know any details about autovivification and I need to look it up.


In reply to Re^4: When DOESN'T "Use of uninitialized value" show up? by Tim McDaniel
in thread When DOESN'T "Use of uninitialized value" show up? by Tim McDaniel

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.