Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Do people find warning for undef with string compare useful?

by perl-diddler (Hermit)
on Feb 11, 2014 at 21:47 UTC ( #1074523=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Do people find warning for undef with string compare useful?
in thread Do people find warning for undef with string compare useful?

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... ;^/...)


Comment on Re^4: Do people find warning for undef with string compare useful?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1074523]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-21 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls