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

P

Perl Learner

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

Jim Keenan

Perl said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top