Just another Perl shrine | |
PerlMonks |
Getopt::Long defaults for options with multiple valuesby PetaMem (Priest) |
on Nov 21, 2014 at 12:23 UTC ( [id://1108001]=perlquestion: print w/replies, xml ) | Need Help?? |
PetaMem has asked for the wisdom of the Perl Monks concerning the following question: Reviewing some middle-aged code, I stumbled across this topic... Unfortunately, the G:L documentation is silent about default values for options with multiple values: Options-with-multiple-values of Getopt::Long. Even more unfortunate seems an inconsistency compared to defaults for options with single values and maybe a semantic inconsistency at all. If you have a single value option, you may define a default like:
This works as expected. Good. You can - of course - do a similar thing for options that take multiple values:
If you omit the -list option, the program will have the default value, which is good. If you, however, will give a list option, G:L seems to push that option to the list already given in default, which may have its applications, but is not that great as default behavior. If you want to actually replace the default given, you would have to define defaults the ugly, backward and programmatically DIY way:
Which is actually code I see right now. Yuck! That can't be right - can it? Bye
Back to
Seekers of Perl Wisdom
|
|