in reply to Parsing the command line: manual or module?
If that's all there was in terms of handling command-line args (if there really was no checking, and no reporting about expected and invalid usage), then the script is nearly unusable. What if the first arg isn't "-f"? What if the next one isn't the name of a config file?# first arguement is a -f; collect it and ignore it for now my $optionalArgument = shift; # get filename of the config file my $configFile = shift;
And as already pointed out, if there's a chance the script will need to be adapted someday to handle additional variations on its behavior, it will be more unusable (and unmaintainable as well) until some sort of Getopt treatment is brought into play.
I use either Getopt::Std or Getopt::Long in many of the command-line scripts I write, and even though I haven't taken the time to memorize all the techniques, even though I have to refer to a previous script or to the module's perldoc output just about every time I use them, it still saves me time, and makes it easier to add new options to my scripts when I need to.
(Having said that, I'll confess that there are also a few occasions when I somehow conclude that I can handle what's needed myself, without Getopt -- but even then, I at least allow for flexibility in the ordering of args, verify that args are as expected, and die with an appropriate error and usage summary when they aren't.)
|
|---|