in reply to Re: better cli processing
in thread better cli processing
A couple of things you will want to read up on.
First, you should look into storing the options in a hash, instead of passing a reference to a variable for each one. It's much easier. See Storing options in a hash for info on that.
Second is aliases, or Options_with_multiple_names. Pretty straight-forward.
Last, you want to look into Bundling for info on allowing the -vds 24 form.
And here's some example code!
#!/usr/bin/perl use warnings; use strict; use Getopt::Long; Getopt::Long::Configure('bundling'); our %Options; GetOptions(\%Options, 'size|s=i', # The | separates aliases, ie: s == size 'verbose|v', # What comes before the | is the name, which 'debug|d', # determines what hash entry (or variable) is +set. ); print "Debug mode\n" if $Options{debug}; print "Verbose mode\n" if $Options{verbose}; print "Size is: `$Options{size}'\n" if exists $Options{size}; print "Done.\n";
This will take --verbose --size=24, or --size 24 -vd, or -vds24, or just about any other combination thereof. :)
bbfu
Black flowers blossum
Fearless on my breath
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (bbfu) (hash, bundling, aliases) Re(2): better cli processing
by flarg (Initiate) on Nov 03, 2002 at 21:09 UTC |
In Section
Seekers of Perl Wisdom