I have been reading the documentation for Getopt::Long but I can't find a way to do what I would like to achive.

Let's restrict it to one option only: verbose. What I would like is to be able to use -v or --verbose only. So -verbose and --verb would both be wrong.

The main code is:

use Getopt::Long; my $verbose=''; GetOptions ( 'verbose' => \$verbose );

However, that accepts -V also. So I change it to

use Getopt::Long qw{:config no_ignore_case};

So far so good, but now --v or -ver both work. I thought I could use bundling like

use Getopt::Long qw{:config bundling no_ignore_case};

but it doesn't quite do what I had in mind.

If I use -ver it correctly says

Unknown option: e Unknown option: r

But if I use --verb (note the double dash) it still recongnises it, which I don't want.

To summarize: if there is one dash then only v is accepted and any other letter should be reported as an 'Unknown option'; if there are two dashes then only the full 'verbose' should be accepted. How can I achive that?

Thanks


In reply to How can I have both short and long options with Getopt::Long? by Anonymous Monk

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.