in reply to Re^3: Warning for checking with undef
in thread Warning for checking with undef
Yes it evaluates to true, because undef is zero numerically regardless of where it came from. It also triggers warnings from each side when the undefined value is coerced into a number, which is exactly what the OP was seeing.
freebie:~ 755> cat quux use warnings; my $foo = undef; if( $foo == undef ) { print "true\n" } freebie:~ 756> perl quux Use of uninitialized value in numeric eq (==) at quux line 3. Use of uninitialized value in numeric eq (==) at quux line 3. + true
Update: Added something that runs inside the conditional to show that it's not being interpreted as a bareword, both sides trigger the undef-used-as-a-number warning, and that the conditional is true without parens.
--
We're looking for people in ATL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |