|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Re: using "Getopt::Long" how to check parameter mandatoryby dasgar (Priest) |
| on Aug 24, 2010 at 18:11 UTC ( [id://856997]=note: print w/replies, xml ) | Need Help?? |
|
What I typically do is take all of the variables that are used in the GetOptions function and initialize them first to a value. For optional parameters, I give their corresponding variables a valid default. For the required parameters, I set their variables to something that I consider to be invalid. Then after calling GetOptions, I do a verification on the variables. Basically if any of the variables now have anything that I consider invalid, I call die and provide an error message. In fact, I usually put the GetOptions and validation in a subroutine and do the initialization outside of that subroutine. Might not be the best method, but that's how I've handled the issue.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||