SPUG: 0 == undef
John W. Krahn
krahnj at acm.org
Wed Apr 7 14:42:50 CDT 2004
On Wednesday 07 April 2004 11:26, Peter Darley wrote:
>
> I'm wondering if there's any way to get 0 to not equal undef. When
> I do:
>
> my ($Test1, $Test2) = 0, undef;
That statement is the same as:
my ($Test1, $Test2) = 0;
undef;
The comma operator (in list context) discards everything after the
first argument. $Test2 is undef because my() sets its arguments to
undef. You need parentheses to create a list:
my ($Test1, $Test2) = ( 0, undef );
> if ($Test1 == $Test2) {print "Crap!\n"}
> else {print "OK\n"}
if ( defined $Test1 and defined $Test2 and $Test1 != $Test2 ) {
print "OK\n"
}
else {
print "Crap!\n"
}
John
--
use Perl;
program
fulfillment
More information about the spug-list
mailing list