Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

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
Posts: 722
Thanks: 3
Thanked 3 Times in 3 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
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 2 Times in 2 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
Posts: 722
Thanks: 3
Thanked 3 Times in 3 Posts
Works like a charm...thanks.
    #4  
Old 03-19-2003
WIntellect's Avatar
Registered User
 

Join Date: Sep 2002
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
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 2 Times in 2 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
how to check null variable sachin.gangadha Shell Programming and Scripting 2 12-06-2007 03:59 PM
not null cheking of an argument in perl ammu Shell Programming and Scripting 4 06-05-2007 09:58 AM
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 05:19 AM.