Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Poor's man command line arguments

by superpete (Beadle)
on Nov 15, 2002 at 01:29 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found