in reply to Getopt::Long via. Hashes

I had similar question, so I re-invented the wheel and wrote my own GetOpts wrapper

app code library code tests more tests

(you can use it if you want to and capable to understand how it works, it's GPLv3. or maybe some day i'll release it on CPAN with product quality and documentation)

Basically I verify options and option combination using plain 'if/else' code, but in separate 'layer' (before program execution), so when program start main work it has already all options validated and possibly reorganized.

And I have DSL to for easier validation layer implementation for easier options definitions

Also the library manages error/warning messages and helps to write unit test for options behaviour with ease

Also you can try to reorganize your command line API and discinct options, commands, positional parameters, and script name aliases. That way complex options will look more sane

Example:

myapp-recaulculate.pl full-recalculate myfile --fast --ignore-errors
instead of
myapp.pl --reculculate --use-full-recalculate --file myfile --fast --i +gnore-errors.
Also, I believe there is more than 100 CPAN modules, related to options processing. You can try to find one that fits your need.

Replies are listed 'Best First'.
Re^2: Getopt::Long via. Hashes
by librarat (Novice) on May 26, 2013 at 19:11 UTC

    Thanks for the code! I half expected a reply such as that - I wound up doing the same thing actually. It's all basic IF/ELSE essentially.

    Cheers!

      Yep, but main thing - separate IF/ELSE from main logic, and don't hesitate to write helper functions for yourself to make IF/ELSE/definitions/error handling easier.

      Also, test your logic with unit tests to prevent regressions!