Actually, "defined" is all I needed.  I don't know why I couldn't find
that myself, but I was really starting to tear my hair out.  Thanks!

- Jesse

-----Original Message-----
From: Andrew Curry [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 14, 2007 3:23 PM
To: Jesse Farrell
Cc: beginners@perl.org
Subject: RE: Recognizing integer as string for if statement

Unless im being very stupid in what your requirements are

If(defined $variable && $variable ne "0") {

}


-----Original Message-----
From: Jesse Farrell [mailto:[EMAIL PROTECTED] 
Sent: 14 August 2007 21:18
To: beginners@perl.org
Subject: Recognizing integer as string for if statement

Is there a way to have a variable recognized as a string even if it
contains
a valid integer?  I have a script that is taking strings from a file
that
can be numbers, including zero.  I have an if statement to simply see if
the
variable exists (otherwise I need to throw an error), and if the
variable
contains 0, the if statement is failing.  Right now, my code is
essentially:

 

if ($variable) {

      # act on $variable

} else {

      # throw error

}

 

Is there an easy way to get the if statement to recognize a 0, or do I
need
to add a special case?  I don't care to keep the 0 as an integer, if I
can
change it to a string somehow, that would work great.

 

--- 

Jesse Farrell 

 



This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the
sender
immediately.  Any opinion expressed in this e-mail is personal to the
sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





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


Reply via email to