Zachary Shay wrote:
Is there a way to test for values where zero is valid?

For instance:

%a_Hash;
$a_hash{"user_id"} = 0;
$a_hash{"user_name"} = "root" if ($a_hash{"user_id"});

print $a_hash{"user_id"} if ($a_hash{"user_id"});
print $a_hash{"user_name"} if ($a_hash{"user_name"});

Sometimes the user_id can be undef.  As a result, if there is no user_id...I
don't concern myself with trying to assign a user_name.

$a_hash{ user_name } = 'root' if defined $a_hash{ user_id };

The problem is that
I believe the zero is being interpreted as false.

Yes.  Perl has four values that are interpreted as "false": undef, 0, '0' and 
''.

Is there a way to test
these values so that only undef will return as false?

perldoc -f defined



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to