Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

PERL: how to tell if variable is NULL

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-18-2003
dangral dangral is offline Forum Advisor  
Registered User
 
Join Date: Oct 2002
Last Activity: 31 July 2013, 6:52 PM EDT
Posts: 723
Thanks: 3
Thanked 4 Times in 4 Posts
PERL: how to tell if variable is NULL

How to I do a check on a variable to see if it's null-- I am using Perl.
Sponsored Links
    #2  
Old Unix and Linux 03-18-2003
oombera's Unix or Linux Image
oombera oombera is offline Forum Advisor  
Registered User
 
Join Date: Aug 2002
Last Activity: 3 October 2004, 6:07 PM EDT
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 6 Times in 5 Posts

Code:
if ($str eq '') {
  <some commands>
}

Sponsored Links
    #3  
Old Unix and Linux 03-18-2003
dangral dangral is offline Forum Advisor  
Registered User
 
Join Date: Oct 2002
Last Activity: 31 July 2013, 6:52 PM EDT
Posts: 723
Thanks: 3
Thanked 4 Times in 4 Posts
Works like a charm...thanks.
    #4  
Old Unix and Linux 03-19-2003
WIntellect's Unix or Linux Image
WIntellect WIntellect is offline
Registered User
 
Join Date: Sep 2002
Last Activity: 29 March 2005, 11:13 AM EST
Location: United Kingdom
Posts: 170
Thanks: 0
Thanked 0 Times in 0 Posts
The function "defined" may also achieve what you require; check the usual perldoc for details.

Linux
Sponsored Links
    #5  
Old Unix and Linux 03-19-2003
oombera's Unix or Linux Image
oombera oombera is offline Forum Advisor  
Registered User
 
Join Date: Aug 2002
Last Activity: 3 October 2004, 6:07 PM EDT
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 6 Times in 5 Posts
Oh that's pretty cool - I don't really like $str eq '' anyway.. i like a more concrete test like isnull(xxx) or something where you can look at it and right away you know what it's testing for.


Code:
my ($some);
$some = "";
if (defined($some)) {
 print "defined";
} else {
 print "not defined";
}

If you remove [$some = "";] you'll see "not defined" instead of "defined".
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Question on NULL and zero value of variable spynappels Shell Programming and Scripting 7 09-28-2011 09:32 AM
how to check null variable sachin.gangadha Shell Programming and Scripting 2 12-06-2007 03:59 PM
test Null variable kykyboss Shell Programming and Scripting 1 11-24-2006 11:02 AM
check for NULL variable esham Shell Programming and Scripting 2 03-20-2005 02:31 AM
How to filter a null variable. gio123bg Shell Programming and Scripting 1 12-19-2003 09:54 AM



All times are GMT -4. The time now is 11:43 PM.