in reply to How do I process many (conflicting) command line parameters?
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*
|
|---|