The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
idea for script - cheking passwords bullz26 Shell Programming and Scripting 5 03-21-2008 06:11 AM
compare null with non-null nitin Shell Programming and Scripting 8 11-04-2006 07:58 PM
Null Value Khoomfire UNIX for Advanced & Expert Users 1 04-10-2006 09:55 AM
argument help brentdeback Shell Programming and Scripting 2 11-27-2005 03:53 PM
PERL: how to tell if variable is NULL dangral Shell Programming and Scripting 4 03-19-2003 01:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-05-2007
ammu ammu is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 79
not null cheking of an argument in perl

Hi,

I have to check whether an argument say $ARGV[1] is not null in an if operator. Please let me know the operator. It would be great if you write a psuedo code.

Thanks in advance
Ammu
  #2 (permalink)  
Old 06-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
A couple of ways to do this.
Code:
VAR=
if [ -z "${VAR}" ] ; then
  echo "VAR contains nothing"
fi
or

Code:
VAR=
if [ x"${VAR}" = x ] ; then
  echo "VAR contains nothing"
fi

edit: My bad. I did not notice that you asked for it in perl

Last edited by vino; 06-05-2007 at 09:03 AM..
  #3 (permalink)  
Old 06-05-2007
ammu ammu is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 79
Hi Vino,

Thanks for replying. I just want to know whether -z will work in perl script.

if it works then the code should be something like

if ( -z "$ARGV[2]" ) then.....fi


Please correct me if I am wrong

Thanks
Ammu
  #4 (permalink)  
Old 06-05-2007
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,417
Code:
if ($ARGV[1] eq "") { print "Empty\n";}
Jean-Pierre.
  #5 (permalink)  
Old 06-05-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Quote:
Originally Posted by ammu
Hi Vino,

Thanks for replying. I just want to know whether -z will work in perl script.

if it works then the code should be something like

if ( -z "$ARGV[2]" ) then.....fi


Please correct me if I am wrong

Thanks
Ammu

for not null checking in perl,

how about using
Code:
if ( ! defined $var  ) {
  print "not defined\n";
}
else {
  print "defined\n";
}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0