Getopt::Long (how to make it die after saying "option requires an argument"?)

Discussion in 'Perl Misc' started by Perl Learner, Jun 13, 2005.

  1. Perl Learner

    Perl Learner Guest

    I am using Getopt::Long to get command line options and I like the fact
    that it gives a warning if the options are not given arguments.

    But the problem is that it gives the warning and the program continues
    to run.

    How do i make it die after saying "option requires an argument" ?

    I think there is a way to "catch" errors but I am unable to figure it
    out.

    Any direction in this regard would help a great deal.

    Thanks.
    Perl Learner, Jun 13, 2005
    #1
    1. Advertising

  2. Perl Learner

    Jim Keenan Guest

    Perl Learner wrote:
    > I am using Getopt::Long to get command line options and I like the fact
    > that it gives a warning if the options are not given arguments.
    >
    > But the problem is that it gives the warning and the program continues
    > to run.
    >
    > How do i make it die after saying "option requires an argument" ?
    >
    > I think there is a way to "catch" errors but I am unable to figure it
    > out.
    >

    The short answer: See the documentation:
    http://search.cpan.org/~jv/Getopt-Long-2.34/lib/Getopt/Long.pm#Return_values_and_Errors

    As I read the docs, you are advised to write a "die" and prepare a
    "die" message for each option defined. (See
    http://search.cpan.org/~jv/Getopt-Long-2.34/lib/Getopt/Long.pm#Return_values_and_Errors.)That
    way, an error will directly guide you to the source of the problem. If
    you don't do that, then the failure to load an option will simply be
    noted as an error, and the overall GetOpts function will emit the
    warning message you are seeing.

    Jim Keenan
    Jim Keenan, Jun 13, 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. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    402
    Natty Gur
    Jan 26, 2004
  2. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    422
    Alvin Bruney
    Jan 25, 2004
  3. Yuri Shtil
    Replies:
    2
    Views:
    2,429
    John Bokma
    Jan 11, 2008
  4. Joel VanderWerf

    getopt/long and ARGV

    Joel VanderWerf, Nov 12, 2006, in forum: Ruby
    Replies:
    0
    Views:
    125
    Joel VanderWerf
    Nov 12, 2006
  5. Sunil
    Replies:
    5
    Views:
    303
    Bart Lateur
    Aug 14, 2003
Loading...

Share This Page