http://qs321.pair.com?node_id=1016191


in reply to Re^2: How come undef eq '' ??
in thread How come undef eq '' ??

I subscribe to this opinion as well.

To me, undef could mean a couple of things, depending on context:

What all of these reasons have in common, is that they essentially mean to represent mu.

If asked the question, "did you stop beating your wife?" then the answer "no" would imply that you still beat your wife. "Yes" doesn't cut it either, because it directly means that you used to beat her. But "mu" or "undef" would mean, "the question does not apply, I have never beaten her."

Therefore, I think that if you're about to do something with a variable (print it, interpolate it, do arithmetic operations with it, throw it against a wall, feed it to your dog), you should either make sure it isn't undef, or explicitly check for its definedness.

Replies are listed 'Best First'.
Re^4: How come undef eq '' ??
by tmharish (Friar) on Jan 31, 2013 at 06:45 UTC

    muba - Makes perfect sense.

    I deal with errors ( such as login fail ) by either Croaking or returning two values so:

    my( $is_success, $return_val ) = this_function_might_return_mu();

    But I see the obvious merit in returning undef - Something I intend to use in the future.