----- Original Message -----
From: Mike Donnelly <[EMAIL PROTECTED]>
Date: Tuesday, December 21, 2004 10:58 am
Subject: Getopt::Long , handles the number zero differently..

Hello
> 
> 
> Using the example code below, I find that I can 

Please paste working code....
>  use getopt handily to pass all sorts of 
>  variables to my script, as long as a 
>  value passed is not a 0 (zero) 

are you sure ??
> 
> How to I use getopt::long and be able to 
>  pass the number zero as a value? 
exactly as you coded below. The problem is not in your getopt code, but in your 
print statment. The OP if $foo, will return false on integer value of 0. 

>  Code, and  behavior follows 
>                           
>                           Thanks! Mike D
> .....................
> MYTEST
> #!/usr/local/bin/perl
> use Getopt::Long;
> GetOptions("o"=>\$oflag,
>             "string=s"=>\$stringmandatory,
>             "int=i"=> \$mandatoryinteger,
> print "oflag $oflag\n" if $oflag;
> print "stringmandatory $stringmandatory\n" if
> $stringmandatory;
> print "mandatoryinteger $mandatoryinteger\n" if
> $mandatoryinteger;
# try this
  print "mandatoryinteger $mandatoryinteger\n" if $mandatoryinteger >= 0;
> 
> print "Unprocessed by Getopt::Long\n" if $ARGV[0];
> foreach (@ARGV) {
>   print "$_\n";
> }
> ................................
> 
> # ./MYTEST --string=abc
> stringmandatory abc
> # ./MYTEST --string=1
> stringmandatory 1
> # ./MYTEST --string=0
> # ./MYTEST --int=0
> # ./MYTEST --int=1
> mandatoryinteger 1

HTH,
Mark G
> 
> 
> 
> 
> 
>               
> __________________________________ 
> Do you Yahoo!? 
> The all-new My Yahoo! - Get yours free! 
> http://my.yahoo.com 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


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


Reply via email to