# first arguement is a -f; collect it and ignore it for now my $optionalArgument = shift; # get filename of the config file my $configFile = shift;
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?

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.)


In reply to Re: Parsing the command line: manual or module? by graff
in thread Parsing the command line: manual or module? by bobf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.