Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Set getopt defaults based on $0

by tilly (Archbishop)
on Jan 13, 2011 at 18:04 UTC ( [id://882191]=note: print w/replies, xml ) Need Help??


in reply to Set getopt defaults based on $0

Using Getopt::Long you can do this by having a section where you declare all of your variables, a second one where you initialize them with default values, then call GetOptions, then have your main script.

So you can do something like this.

my ($action, $type, $foo, (other variables)); my $name = $0; $name =~ s~.*/~~; my ($verb, $object) = split /-/, $name; $action = $verb; # Case statement for defaults for verb. # Case statement for defaults for object. # Case statement for defaults for name (combines verb + object) GetOptions( "action=s" => \$action, "type=s" => \$type, "foo=i" => \$foo, ... ); and more program
If you're using Perl 5.10 or better you can use feature "switch"; at the beginning and then:
given($object) { when ("tap") {$type = "domestic"} .... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-16 22:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found