GetOptions \our %Cmdline, qw(input|i=s output|o=s foo=i bar:i baz);
To tell the truth "=s" is the only spec I really use nine times out of ten :)
The nice thing about this is that I get a global with convenient longnames that are the same as the longnames on the command line: $Cmdline{input} etc.
Sure, there's a lot missing here. This doesn't wire into the POD of my script, and it doesn't generate --usage notes. And those are tedious to write and there are "better" modules out there. They aren't core, though, and some have other disadvantages, so for casual programming with Perl 5, I stick to Getopt::Long.
Recently in a larger project I've used App::CLI (although App::Cmd seems similar yet more featureful, I had deployment issues with it). YMMV.
ObPerl6: in Perl 6, this is so much better :) The entry point to your program is always a subroutine called MAIN, and get this, the signature (Perl 6 has function signatures) captures the command line arguments for you (Perl 6 has function signatures powerful enough to express almost anything you'd care to spec on the command line). Nifty!
In reply to Re: Seeking Getopt recommendations - anyone used Getopt::Easy?
by gaal
in thread Seeking Getopt recommendations - anyone used Getopt::Easy?
by theguvnor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |