FAQ
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

Search Discussions

  • Ronald J Kimball at Mar 25, 2005 at 10:18 pm

    Vergara, Michael (TEM) wrote:

    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";
    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?
    This is not a DBI question. Please ask your questions in the appropriate
    forum.

    Since I'm feeling helpful at the moment, I will point out that you are
    checking whether the option is true; you should be checking whether it
    exists.

    if ( exists $optctl{z} ) {

    HTH,
    Ronald
  • Ian Harisay at Mar 25, 2005 at 10:31 pm
    This is the wrong forum for this kind of question. But try this instead
    it will give you a much clearer picture.

    use Getopt::Long;
    use Data::Dumper;
    my %optctl;
    Getopt::Long::GetOptions(\%optctl, 'x!', 'z!') or die \nOption
    Error\n\n;

    print Dumper(\%optctl),$/;
    Vergara, Michael (TEM) <mvergara@guidant.com> 03/25 2:59 pm >>>
    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
  • Tim Bunce at Mar 25, 2005 at 10:48 pm

    On Fri, Mar 25, 2005 at 01:59:05PM -0800, Vergara, Michael (TEM) wrote:

    What am I not seeing?
    That this list is for DBI related issues. Sorry, but discussing other topics
    is an abuse of the list and the time of its thousands of subscribers.

    This'll help explain why that's important:
    http://www.catb.org/~esr/faqs/smart-questions.html

    Tim.
  • Vergara, Michael \(TEM\) at Mar 27, 2005 at 5:28 am
    Oops. My apologies to all. I must've picked the wrong Perl group
    from the address list.

    Ron, Thanks!

    Cheers,
    Mike

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedMar 25, '05 at 9:59p
activeMar 27, '05 at 5:28a
posts5
users4
websitedbi.perl.org

People

Translate

site design / logo © 2022 Grokbase