Misunderstood use of Getopt::long

From: Michael \ Vergara (mvergara_at_guidant.com)
Date: 03/25/05


Date: Fri, 25 Mar 2005 13:59:05 -0800
To: <dbi-users@perl.org>

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


Relevant Pages

  • Re: Misunderstood use of Getopt::long
    ... Getopt::Long::GetOptionsor die \nOption ... my %optctl =; ... print header = $headerFlag\n; ... print duplex = $duplexFlag\n; ...
    (perl.dbi.users)
  • Re: Using the field {PRINT 27 &l1S} for duplex in Word 2K - SOLUTION
    ... this has to go at the top of* each page after the duplex command on ... * although the help files and knowledge base articals regarding this state ... I put the duplex code is in the header, ...
    (microsoft.public.word.pagelayout)
  • Re: [OT] Survey: die vs. exit
    ... > preference says something about you... ... > Personally I die() most of the times. ... I'll throw an 'exit' in after a header() ...
    (comp.lang.php)
  • Re: CGI::Carp die with status
    ... A simple CGI example script is: ... die "Some error occured...\n"; ... I would like the status header not to print 200 OK, ... status header when the script dies with fatalsToBrowser as above. ...
    (comp.lang.perl.misc)
  • Re: CGI::Carp die with status
    ... die "Some error occured...\n"; ... I would like the status header not to print 200 OK, ... status header when the script dies with fatalsToBrowser as above. ...
    (comp.lang.perl.misc)