PERL: how to tell if variable is NULL | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

PERL: how to tell if variable is NULL

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 03-18-2003
oombera's Avatar
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 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 03-19-2003
WIntellect's Avatar
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.

Sponsored Links
    #5  
Old 03-19-2003
oombera's Avatar
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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:32 AM
how to check null variable sachin.gangadha Shell Programming and Scripting 2 12-06-2007 04:59 PM
test Null variable kykyboss Shell Programming and Scripting 1 11-24-2006 12:02 PM
check for NULL variable esham Shell Programming and Scripting 2 03-20-2005 03:31 AM
How to filter a null variable. gio123bg Shell Programming and Scripting 1 12-19-2003 10:54 AM



All times are GMT -4. The time now is 12:35 AM.