HidyHo, folks...
More of an 'approach' question, than specific to Perl...
I've been building a LOT of programs in recent years that use command line switches for some inputs... but I'm now getting to a bit more of a complex situation... and I'm not sure about the 'best' (standard?) way to deal with it.
Firstly, I now have programs that may need to process many command line switches. The actual switches are simple enough (for example, "-v" for "verbose logging" or "-t 10" for "timeout time") ...but many of the switches are mutually exclusive... so how to process/validate these items!?
Initial thoughts include simply setting 'flag variables' for each switch... and I set the flag if I see it when dealing with the command line... and I later have a function that simply does all the ANDing and ORing etc to see what flags are set/clear.
Alternatively, I sometimes have set-up a bitfield to represent the state of each switch... and as I find a switch on the command line, I set that bit in a 'status value'... and I then have something that checks for 'magic numbers' (ooo, bad!) that represent the invalid combinations of bits... but maybe there's a better/simpler (or more standardized) way?
The other issue is that I have a lot of functionality in some of these programs... and to select the particular action I want to perform is getting a bit ugly/hairy to deal with and I could, conceivably, end-up dealing with too many command line switches for the "-f value" -style of parameter (which I would like to maintain -- I don't want to have to deal with the complexities of weirdo syntaxes like "-p input='a,b'-12'" ...!)
For now, I'm simply using a construct like "-a 1" to say "run action 1" and I explain the actions/numbers/functionality in the help output (which is getting to be more than a couple of paragraphs of explanation... Ugh).
As usual, I'm building these Perl programs under Win32 (maybe to run under Win64, too?) and Linux, using v5.16.x, v5.20.x and beyond.
Many thanks for any thoughts...
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |