SPUG: Re: 0 == undef
Aaron W. West
tallpeak at hotmail.com
Wed Apr 7 14:39:07 CDT 2004
Good point, I'd think...
It's rather the opposite of null propogation in SQL, where a comparison with
null always fails.
[MSSQL]
select
case when 0=null then '0=null' else '0<>null' end,
case when 1=null then '1=null' else '1<>null' end,
case when null=null then 'null=null' else 'null<>null' end
------- ------- ----------
0<>null 1<>null null<>null
(1 row(s) affected)
Not that undef and null mean exactly the same thing...
So you have to use defined tests if undef's are expected...
cygwin bash & windows cmd.exe-compatible command-line... (can't use
double-quotes within double quotes in cmd.exe, in my experience)
perl -e "print map {qq($_\t=\t[) . (eval $_) . qq(]\n) } qw(0==undef
undef==undef undef==qq() undef==1)"
0==undef = [1]
undef==undef = [1]
undef==qq() = [1]
undef==1 = []
----------
Quoting in CMD.EXE is very very weird.
This command runs, but prints only a, nothing else:
perl -e "print ""a""";print 1;""
a
Note the necessity of a triple-quote to end the string. Without that I get
Can't find string terminator...
Also, there's no such thing as line-continuation (backslash in bash)
Oh well, cmd.exe sucks, we all know it...
----- Original Message -----
From: "Peter Darley" <pdarley at kinesis-cem.com>
To: "SPUG" <spug-list at mail.pm.org>
Sent: Wednesday, April 07, 2004 11:26 AM
Subject: SPUG: 0 == undef
Folks,
I'm wondering if there's any way to get 0 to not equal undef. When I do:
my ($Test1, $Test2) = 0, undef;
if ($Test1 == $Test2) {print "Crap!\n"}
else {print "OK\n"}
I find out that 0==undef.
I'm also wondering what the thinking here is?
Thanks,
Peter Darley
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at mail.pm.org http://spugwiki.perlocity.org
ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, Location Unknown
WEB PAGE: http://www.seattleperl.org
More information about the spug-list
mailing list