in reply to Re^7: Regex result being defined when it shouldn't be(?)
in thread Regex result being defined when it shouldn't be(?)

 defined($var)==0
Use of uninitialized value in numeric eq (==)

use strict; use warnings; my $variable = undef; if( undef == 0 ){ print "undef == 0\n"; } if( $variable == 0 ){ print "\$variable undef == 0\n"; } if( "" == 0 ){ print "\"\" == 0\n"; } if( undef eq 0 ){ print "undef eq 0\n"; } if( undef eq 0 ){ print "\$variable undef eq 0\n"; } if( undef eq "" ){ print "undef == \"\" \n"; } if( 0 == "0" ){ print "0 == \"0\"\n"; } if( 0 eq "" ){ print "0 eq \"\""; } if( undef eq "" ){ print "undef == \"\"\n"; } if( defined ($variable) eq "" ){ print "undef == \"\"\n"; } exit 0;
The last two cases may be of particular interest. undef is uninitialized as itself or from a variable, but as the result of defined it is not uninitialized. Magic conditions. I'm running Perl 5.26.1

Nvm: doy. Defined returns "" on undef.

Replies are listed 'Best First'.
Re^9: Regex result being defined when it shouldn't be(?)
by soonix (Chancellor) on Nov 18, 2017 at 11:32 UTC
    defined($var)==0
    Do you also write conditios as
    if ( ($var < $threshold) == TRUE ) ...
    ? Then why not
    if ( ( ($var < $threshold) == TRUE ) == TRUE ) ...
    or more?