As has been suggested, Getopt::Long is the module you want. You can find dozens of examples online on how to use this option. Google it, if you can't do the CPAI^HN thing. Create a seperate usage subroutine and redirect all bad options to that, and once you make your initial call to getopt, if you find that the argument array still has things in it, you can flag an error on that too.

Rather than trying to solve your whole problem, I suggest you write a little test program just for getopt, and play with that. It comes in handy if you need to write any additional scripts, as getopt is generally the first thing EVERY perl script does. That's generally good advice is to test out a new feature in a tiny program before you apply it to whatever big program you're attempting to use.

Good luck, --Ray


In reply to Re: command line switches (array) by raybies
in thread command line switches (array) by blackice69

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.