you get the warning if and only if, due to the operation it's being used in, Perl has to convert an undef value to a string ("") or number (0)?

Bingo.

Addition wants a number. If you don't pass a number, the value gets coerced into a number. Coercions from undef warn.

A truth test doesn't require or cause coercion, so there's no coercion that can warn.

What contexts are there for use of undef?

What does that mean? Are you asking what behaviour an operator can take when passed undef as one of its operand? Well, that's entirely up to the operator.

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.

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

You might be interested in no autovivfication;, though.


In reply to Re^3: When DOESN'T "Use of uninitialized value" show up? by ikegami
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.