Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How do I process many (conflicting) command line parameters?

by Discipulus (Canon)
on Jun 30, 2017 at 01:19 UTC ( [id://1193878]=note: print w/replies, xml ) Need Help??


in reply to How do I process many (conflicting) command line parameters?

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.

Log In?
Username:
Password:

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

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

    No recent polls found