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. Advertisements

  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. Advertisements

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:
    643
    Natty Gur
    Jan 26, 2004
  2. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    699
    Alvin Bruney
    Jan 25, 2004
  3. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    971
    Eric Sosman
    Jul 8, 2003
  4. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,577
    Peter Shaggy Haywood
    Sep 20, 2005
  5. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    697
    santosh
    Jul 24, 2007
  6. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    1,242
    Peter Nilsson
    Jan 15, 2008
  7. veryhotsausage
    Replies:
    1
    Views:
    2,353
    veryhotsausage
    Jul 4, 2008
  8. Oliver Graeser
    Replies:
    10
    Views:
    819
    Oliver Graeser
    Sep 26, 2008
Loading...