Looking through old stuff... I saw
mysub($user_data) { $user_$data->{invoice_number} ... } mysub({age => $user_age, inovice_number = $invoice_number}) # TYPO!
For most people the above would be caught by warnings+strict ... using an undeclared var, and/or only 1 use of the var. So never happens. Vs. here you say:
a code to avoid bug:
defined($x) or confess;
--- A program that dies unexpected has a bug. You didn't avoid a bug, but caught it and displayed it to the user.

I guess in my programs, I rely on "undef" as a valid and useful value to mean something that isn't initialized yet and/or has not been assigned a value yet..

Example -- in a web-reading program, I had a value $p->{content}, that kept coming back "undef" after I got the content back from an html library. The call returned '0', to indicate it had succeeded in querying the server, but somewhere, it set some error value to '404' (that I couldn't easily find in the documentation) -- but it was then I realized, that 'content' was undef not due to any bug -- but because that's is what was returned from the website! Undefined/uninitialized content. Once I figured that out, I could handle it as some sort of read error and retry or ignore the call later. I think I eventually found the place for the error to be returned -- in an 'async-handler' call to an error routine. Not what I was expecting.

In the above -- if I was checking if a mirror of the site was the same as another, comparing 'undef' against 'undef' would be a desirable operation -- it means both didn't return an object for 'something' (providing it is only a few objects). If it returns randomly or too often, something else may be wrong.

(unlikely anyone reads these old replies -- too bad there's not a notification to people when someone has replied to one of their messages, ..vs. the current method of looking at all your posts and going through them 1-by-1 and looking to see if there are new responses... ;^/...)


In reply to Re^4: Do people find warning for undef with string compare useful? by perl-diddler
in thread 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.