Getopt::Std , option with no argument

Discussion in 'Perl Misc' started by hymie!, Dec 27, 2005.

  1. hymie!

    hymie! Guest

    Greetings.

    I've run across this issue:

    #!/usr/bin/perl
    use Getopt::Std;
    getopt('l');
    print "$opt_l\n";

    eric@db01:~/last_update$ ./test.pl -l5
    5
    eric@db01:~/last_update$ ./test.pl -l larry
    larry
    eric@db01:~/last_update$ ./test.pl -l

    eric@db01:~/last_update$

    perldoc tells me:
    For each
    switch found, sets $opt_x (where x is the switch name) to
    the value of the argument, or 1 if no argument.

    However, that doesn't seem to be happening. $opt_l is not being set to
    1 when there is no argument.

    Is this my fault?

    Thanks.

    hymie! http://www.smart.net/~hymowitz hymie_@_lactose.homelinux.net
    ===============================================================================
    He's neurotic, which is Jewish for "intense." --Cybill
    ===============================================================================
     
    hymie!, Dec 27, 2005
    #1
    1. Advertising

  2. hymie!

    hymie! Guest

    In our last episode, the evil Dr. Lacto had captured our hero,
    hymie_@_lactose.homelinux.net (hymie!), who said:
    >Greetings.


    I don't know if my "cancel" will work or not, but about 5 minutes after
    I posted, I found this:

    http://groups.google.com/group/perl...read/thread/5a705619506b39c5/36198c4d3ecc0ed7

    which contains this crucial paragraph:

    Not all options handled by getopt() are expected to have a value. With
    getopt('xy'), -x and -y expect an argument, and all other options do not
    expect an argument. perl foo -x -y -z will set $opt_x to '-y' and $opt_z
    to 1.

    and solved my problem.

    hymie! http://www.smart.net/~hymowitz
    ===============================================================================
     
    hymie!, Dec 27, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Rawson
    Replies:
    4
    Views:
    552
    Jeff Epler
    Sep 19, 2003
  2. David Shapiro

    python and getopt and spaces in option

    David Shapiro, Jun 9, 2009, in forum: Python
    Replies:
    1
    Views:
    812
    Jorgen Grahn
    Jun 10, 2009
  3. Sunil
    Replies:
    5
    Views:
    349
    Bart Lateur
    Aug 14, 2003
  4. Perl Learner
    Replies:
    1
    Views:
    207
    Jim Keenan
    Jun 13, 2005
  5. Davy
    Replies:
    2
    Views:
    109
    Paul Lalli
    Aug 20, 2006
Loading...

Share This Page