Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: command line args - a chicken and egg problem

by Helter (Chaplain)
on Apr 13, 2006 at 15:12 UTC ( [id://543114]=note: print w/replies, xml ) Need Help??


in reply to command line args - a chicken and egg problem

My typical command line parsing goes something like this:
use vars qw/ $opt_help $opt_one $opt_two $opt_config /; sub parseCommandLine(); parseCommandLine(); ...... ...... sub parseCommandLine() { &getOptions( 'help|h', 'config|c=s', 'one', 'two=s' ) or $opt_help += 1; if( defined( $opt_help ) ) { &printUsage(); exit(0); } if( defined( $opt_config ) ) { &parse_config( $opt_config ); } if( defined( $opt_one )) { # do extra setup required for option 1 } else { $opt_one = 'default_opt_one'; } unless( defined( $opt_two ) ) { $opt_two = 'default_opt_two'; } # Do stuff needed for option 2. } sub parse_config( ) { my $config_file = shift(); # read file # use file to set $opt_one, $opt_two }
Hope this helps...Untested code of course :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found