Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

(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. :)

Black flowers blossum
Fearless on my breath

Comment on (bbfu) (hash, bundling, aliases) Re(2): better cli processing
Select or Download Code
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
    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 studying the Monastery: (5)
As of 2015-11-29 19:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (752 votes), past polls