Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Re: Poor's man command line arguments

by superpete (Beadle)
on Nov 15, 2002 at 01:29 UTC ( #213050=note: print w/replies, xml ) Need Help??

in reply to Re: Poor's man command line arguments
in thread Poor's man command line arguments

here's how I used to do it before I learned getopt:

it uses grep, puts your arguments in a hash, and you can easily set defaults, and it automatically makes your "usage" string, and it automatically rejects invalid arguments. arguments are in "option=value" style to avoid ambiguity

#!/usr/bin/perl -w # set defaults here %args = ( width => 750, height => 600, invert_threshold_factor => 0.25, invert => -1, pscanhome => "/home/lab/pscan", color_a => "darkcyan", color_b => "darkred"); $options = '[' . (join '=?] [', sort keys %args) . '=?]'; $usage = "usage: $0 $options picname\n"; $name = pop || die $usage; foreach (@ARGV) { my ($a, $b) = split '='; die $usage unless grep {$a eq $_} keys %args; $args{$a} = $b; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-02-26 01:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found