note
jhourcle
<blockquote><i>Sometimes 0 is an acceptable value. You account for that by using if ($value or $value == 0).</i></blockquote>
<p>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 <code>eq</code> instead of <code>==</code> :</p>
<code>($value or $value eq 0)</code>
<readmore><code>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;</code><p>generates:</p><code> 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</code></readmore>
598879
598956