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

Re: undef == 0?

by samtregar (Abbot)
on Oct 24, 2007 at 16:52 UTC ( #646945=note: print w/replies, xml ) Need Help??

in reply to undef == 0?

I suppose you prefer something like SQL's tri-state logic. Frankly, I find (NULL = NULL) being NULL much more confusing than (undef == 0) being true!


Replies are listed 'Best First'.
Re^2: undef == 0?
by stu42j (Sexton) on Oct 24, 2007 at 17:42 UTC
    Yeah, I was thinking somewhere along the lines of how SQL treats NULLs. Although I suppose that instinctively, I would expect undef == 0 to be false but undef == undef to be true. Not that it would be right in any way.
Re^2: undef == 0?
by snopal (Pilgrim) on Oct 24, 2007 at 18:29 UTC

    Tristate... you said the magic word!

    my $test = return_from_function(); if (not defined $test) { # do this if evaluates to undefined } elsif (!$test) { # do this if evaluates to zero equivalent } elsif ($test) { # do this if evaluates to non-zero equivalent }

    If you really wanted, you could throw in a $test eq '' in there too, but I've found that to be gratuitous code abuse.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-09-26 23:09 GMT
Find Nodes?
    Voting Booth?

    No recent polls found