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.


In reply to Re: Prioritizing command line options by VSarkiss
in thread Prioritizing command line options by kvh009

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.