Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

by bbfu (Curate)
on Nov 02, 2002 at 23: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. :)

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 16:09 UTC
    Beautiful. That's exactly what I was looking for. Thanks all!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2020-10-24 04:11 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (242 votes). Check out past polls.