I was wondering (and thinking, w.r.t how code might be simplified), in the case where you compare an 'undef' value with any other value using literal (vs. numeric) operators, how it benefits people by having perl issuing a warning for comparing undef to something (including undef).

I was thinking on how one might silence that warning but NOT the warning if used in numeric comparisons (i.e. undef != $x), but couldn't think of an easy way since as the same warning message is used when concatenating string values.

I find the warning more useful in the case of trying to combine undef with a string, which people see most often when using print/printf to print a value that isn't defined. Without that warning, one wouldn't know the difference between a print w/undef vs. a print w/an empty string ('' or ""). Also, that usage can be trapped and compensated for in 1 place (the print routine -- that was the original motivation of the P module -- a safe way to print things without warnings, which usually are often set to terminate programs under the motto of "die early, die loudly (informatively)".

Under the current methodology, one has to use 2 checks to protect against that warning -- and it seems like that's one check too many for what, in my code, is a common case. That said, though, I realize there is a wide variety of coding idioms, and my find it hard to see such a question "objectively" -- so I thought I'd ask on here. How do you find those warnings use? I.e. what would be the compatibility issue with not issuing warnings in those circumstances?

Is that warning beneficial?

Note -- am talking about use of 'undef' with 'eq' and 'ne'. It's already the case that using 'undef' with 'or', 'and' and 'not' allow an operand to be 'undef' without accompanying warning messages.

How do people find the warning useful for 'eq'/'ne'?


In reply to Do people find warning for undef with string compare useful? by perl-diddler

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.