develooper Front page | perl.dbi.users | Postings from March 2005

Misunderstood use of Getopt::long

Thread Next
From:
Vergara, Michael
Date:
March 25, 2005 13:59
Subject:
Misunderstood use of Getopt::long
Message ID:
6453043A231BE2438C40BF73F7A65BA50373B812@TEMEVS01.tem.guidant.com
Hi All:

I have this code...
#!/opt/perl64/bin/perl -w
# v5.8.4 built for PA-RISC2.0-LP64
use Getopt::Long;
my %optctl = ();
Getopt::Long::GetOptions( \%optctl, "x!", "z!")
or die "\nOption Error\n\n";
my( $headerFlag, $duplexFlag );
if ( $optctl{z} ) { $headerFlag = $optctl{z}; }
  else { $headerFlag = 1 };
if ( $optctl{x} ) { $duplexFlag = $optctl{x}; }
  else { $duplexFlag = 0 };
print "header   = $headerFlag\n";
print "duplex   = $duplexFlag\n";

When I run it, I get this:
$ ./p
header   = 1
duplex   = 0
$ ./p -x
header   = 1
duplex   = 1
$ ./p -x -noz
header   = 1
duplex   = 1
$ ./p -nox -noz
header   = 1
duplex   = 0

My problem is that header is always 1 and I don't think it should be
when I specify "-noz".   If I can toggle the value of the 'x' option,
why not the 'z' option?

What am I not seeing?

Thanks,
Mike

---
======================================================================
Michael P. Vergara
Oracle DBA
Guidant Corporation
www.guidant.com



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About