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. The problem is that
I believe the zero is being interpreted as false. Is there a way to test
these values so that only undef will return as false?
Use the 'defined' built-in function:
print $a_hash{user_id} if defined $a_hash{user_id};
print $a_hash{user_name} if defined $a_hash{user_name};
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/