in reply to How do I process many (conflicting) command line parameters?
Regarding the conflict between options... perhaps this (KISS in play):-
# to check on conflicting switches use Getopt::Std; # Switches and Invalid combinations # NOTE: conflicts must be specified in alphabetical order! @switches = (); # List of supplied switches @switch_conflicts = ( "lp", # portrait and landscape "lpv", # portrait, landscape, view-only "pv" # portrait, view-only ); # ---------- getopts("plv"); # ---------- Specify switches on CLI if (defined($opt_p)) { push(@switches, "p"); } if (defined($opt_l)) { push(@switches, "l"); } if (defined($opt_v)) { push(@switches, "v"); } $switch_list = ""; foreach $item (sort @switches) { $switch_list .= $item; } # ------ foreach $item (@switch_conflicts) { if ($switch_list =~ /$item/) { # Get out at earliest opportunity printf("\nERROR: Invalid combination of switches, /%s/\n", $ite +m); die("\n"); } } printf("\nSwitches are all Ok.\n"); exit(0);
The main thing with doing things this way is that it's relatively simple to add a new switch (and its conflicts), update the 'getopts()' string and add an additional (basic) 'opt_x'... and it should be easy enough to turn this whole thing into a sub{} or similar...
Any other thoughts?
Fanx! again for all the posts... and I'm still pondering the switch checking/function execution side of things...
|
|---|