hello ozboomer,

interesting question. For the basic approach i totally agree with above Anonymous Monk.

Me too I ussume you are using Getopt::Long module with all it's features.

More: if I erase some value fidded by command line and the application is somehow risky I'd print th to the screen the resulting command line arg line and I'd ask for confirmation.

Having excluding parameters can be complex and I saw not a lot of examples of managing it.

What I can imagine for a very big number of, potentially, mutually exclusive parameters can be similar to an dispatch table.

You can associate references to all variables you assigned via Getopt::Long to some code to be run. Better: you can use an array for the dispatch table, processing rules from 0 to the last one and doing so giving priority to more important arguments.

Let's say you have --chars num that sets $chars and also --display name that that sets $display{name}

If $display{name} is tv you want to assign a different value to $chars and clean the --monochromo $bw switch

#PSEUDOCODE # setting deafult is useful my $chars = 70; # chars per line my %display = (name=>'screen'); my $bw; # not monochromo by default # Getopt::Long part assign command line provided values to $chars and +$display{name} .. # validation and exclusion my @checks = ( [\$display{name}, sub{ if ($display{name} eq 'tv'){ $chars = 35; $bw = undef; } print "--display tv sets --chars to 35 and c +lean --monochromo\n" }], [\$chars, sub{die "chars 12-140!" if ($chars<12 || $chars>140)} ], [\$bw, undef] ); foreach my $i (0..$#checks){ if defined the 0th element and also the first one, execute the latt +er

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: How do I process many (conflicting) command line parameters? by Discipulus
in thread How do I process many (conflicting) command line parameters? by ozboomer

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.