Greetings monks,

This seems like such a simple idea, but I can't seem to find any module that does it. I have a script that needs to take in a bunch of command line options in an open-ended set. I don't want to name them all in the script. So I want a GetOptions() function that has the ability to just process the command line arguments and treat the things that look like options as if they were options and not throw up all over my screen just because I didn't tell it ahead of time that this these options might be coming in. (And also not just ignore them and leave them in @ARGV.)

perl -s kind of does this, but I need it to be able to handle long options names that take values and don't require '=' between option name and value. I guess I'd like to see an addition like this for Getopt::Long::GetOptions:

use Getopt::Long; GetOptions( opta => \$opta, 'optb=s' => \$optb, '=s' => \%others, #here's the new thing. );
where '=s' says for anything else that looks like a command line options process it as if it were and as if it required a string argument, stuffing the results as key/value pairs in %others.

Or am I just being dense and there's some really straightforward way to do this that I'm not seeing?

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."


In reply to Parsing command line options without knowing what they are by DrWhy

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.