Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

(bbfu) (hash, bundling, aliases) Re(2): better cli processing

by bbfu (Curate)
on Nov 03, 2002 at 04:33 UTC ( #210033=note: print w/ replies, xml ) Need Help??


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


Comment on (bbfu) (hash, bundling, aliases) Re(2): better cli processing
Select or Download Code
Re: (bbfu) (hash, bundling, aliases) Re(2): better cli processing
by flarg (Initiate) on Nov 03, 2002 at 21:09 UTC
    Beautiful. That's exactly what I was looking for. Thanks all!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://210033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-07-14 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (260 votes), past polls