I've written some function with multiple options. Suddenly I'm up to > 13 arguments, with most of the places I invoke it passing nulls in most of the args. Of course, this is error prone and difficult to maintain.
My background is writing LISP code. I'm used to its keyword style of function-definition. In spirit, it is very similar to Getopt. My inclination is to rewrite the function definition to use Getopt. But it seems I never see Getopt used down in function definitions; I only see it processing the arguments to scripts. Are there good reasons to shy away from code of the form
use Getopt::Std;
sub foo{
my($opt_a, $opt_b, $opt_c, $opt_d);
getopts('abc:d:');
...}
Efficiency won't be a concern here; my main concerns are clarity of the code, maintainability and portability.
Also, if Getopt::Std gets the job done, is there any particular reason1 to use any of the other half-dozen or so 'Getopt' modules at CPAN instead?
throop
1Other than the fact that
most people's first thought whent they see STD is 'Sexually Transmitted Disease' or 'Severe Tire Damage'.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.