> -----Original Message-----
> From: Zachary Shay [mailto:[EMAIL PROTECTED] 
> Sent: Monday, September 24, 2007 11:04
> To: beginners@perl.org
> Subject: How to test for "0"
> 
> 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 
        In Perl zero is false and non zero is true. You can try:
        if ( exists $a_hash{"user_id"} ) {
                # place what you want to do if the particular user_id
does exist
         } 

        A thought.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us 

> way to test
> these values so that only undef will return as false?
> 
> Thanks,
> Zach
> 

**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


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


Reply via email to