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:
because initially, there is no previous line yet, and setting $previous to "" initially would make it look like the previous line was just an empty line. There is a difference between "no previous line" and "previous line was empty")my $previous = undef; while (my $line = <$filehandle>) { chomp $line; ...; # process $line $previous = $line; }
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 |