in reply to Re: Check Variables for NULL
in thread Check Variables for NULL

Sometimes 0 is an acceptable value. You account for that by using if ($value or $value == 0).

This may be more inclusive than you wish. (it will be true for both undef and the empty string), as it's basically asking for everything that's true or everyhing that's false. You likely wanted eq instead of == :

($value or $value eq 0)
my %values = ( 0 => 0, zero => '0', undef => undef, empty => '', 1 => 1, one => '1', string => 'string', ); printf ("%6s : %i : %i :: %i :: %i\n", $_, ($values{$_}?1:0), ( $values{$_} == 0), (($values{$_} or $values{$_} == 0)?1:0), (($values{$_} or $values{$_} eq 0)?1:0)) foreach sort keys %values;

generates:

0 : 0 : 1 :: 1 :: 1 1 : 1 : 0 :: 1 :: 1 empty : 0 : 1 :: 1 :: 0 one : 1 : 0 :: 1 :: 1 string : 1 : 1 :: 1 :: 1 undef : 0 : 1 :: 1 :: 0 zero : 0 : 1 :: 1 :: 1