Don't ask to ask, just ask | |
PerlMonks |
Re^3: Parsing options with Getopt & Dispatch Tableby broomduster (Priest) |
on Feb 18, 2011 at 15:56 UTC ( [id://888933]=note: print w/replies, xml ) | Need Help?? |
Updated: Just learned that the special option 'name' "<>"
can be used to designate a subroutine to
handle non-option arguments (see Argument callback section in the docs).
So the following is not entirely correct w.r.t. a "default option"...
Getopt::Long has lots of configuration options that have their own defaults, but there's no option to define a default option and default value/behavior for it. You need to do that for yourself, but Getopt::Long can help. One of its default behaviors is to flag as errors “Options that are unknown, ambiguous or supplied with an invalid option value” (see the pass_through configuration option). So if you do nothing special, GetOptions() will tell you when you use an unknown option on the command line. Using cjb's sample as a start, this shows what happens when you include an unknown option on the command line: And run like so (only defined options):
or thusly (one defined and one undefined option):
Comments:
In Section
Seekers of Perl Wisdom
|
|