Mike Donnelly wrote:

Using the example code below, I find that I can use getopt handily to pass all sorts of variables to my script, as long as a value passed is not a 0 (zero) How to I use getopt::long and be able to pass the number zero as a value? Code, and behavior follows .....................
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;

Change the previous three lines to:

 print "oflag $oflag\n" if defined $oflag;
 print "stringmandatory $stringmandatory\n" if defined $stringmandatory;
 print "mandatoryinteger $mandatoryinteger\n" if defined $mandatoryinteger;


print "Unprocessed by Getopt::Long\n" if $ARGV[0];

Change that one to:

 print "Unprocessed by Getopt::Long\n" if @ARGV;

($ARGV[0] could also be "0"!)


 foreach (@ARGV) {
   print "$_\n";
 }


John
--
use Perl;
program
fulfillment

--
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