Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Prioritizing command line options

by VSarkiss (Monsignor)
on Jan 19, 2002 at 02:54 UTC ( [id://139981]=note: print w/replies, xml ) Need Help??


in reply to Prioritizing command line options

You don't show what's in file, but why not just use another option variable? (Note, this is untested.)

my %help_options = ( "color!" => sub { $options{USE_COLOR_CMDLINE} = $_[1] }, "conf=s" => sub { $options{CONF} = $_[1] }, ); GetOptions( %help_options ); do $options{CONF} if defined $options{CONF}; # Override it if specified on the command line. $options{USE_COLOR} = $options{USE_COLOR_CMDLINE} if exists $options{USE_COLOR_CMDLINE};
That's not necessarily the easiest or best way to accomplish it, but it's probably the smallest change to your example code that would do it.

On a separate note, I cringe at the idea that your program variables are spread among its own and the external file. (In other words, the external file knows the name of the %options hash and the particular key values, so if you change one you have to change the other.) I'd much rather use a "ini" style file with var = value pairs or some such, where I can map the keys to my variables through a hash or something. Of course, I don't know what limitations you're working under, so maybe this isn't practical for you, but if it is, I'd really recommend the change.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found