I’m using Perl’s Getopt::Long module to parse command line arguments. However, it seems that it returns a true value even if some of the arguments are missing. Is there a way to tell if this is the case?
I’m using Perl’s Getopt::Long module to parse command line arguments. However, it seems that
Share
In plain old Getopt::Long, you can’t do this directly — as Jonathan said, you need to check your requirements for undef. However, IMHO this is a good thing — what is a “required” parameter? Often one has parameters that are required in one case and not another — the most common example here being the sore thumb of the
--helpoption. It’s not required, and if the user uses it, he probably doesn’t know to or won’t pass any of the other “required” parameters.I use this idiom in some of my code (well, I used to, until I switched to using MooseX::Getopt):
Even with MooseX::Getopt I don’t set my attributes to
required => 1, again because of the--helpoption. Instead I check for the presence of all attributes I need before moving into the main body of program execution.