in reply to How can I have both short and long options with Getopt::Long?

use strict; use warnings; use Getopt::Long qw( :config posix_default bundling no_ignore_case ); GetOptions('verbose|v' => \my $opt_verbose) or die("usage\n"); print( $opt_verbose || 0, "\n");

The ones that should work:

>perl 806754.pl -v 1 >perl 806754.pl --verbose 1

The ones that shouldn't work:

>perl 806754.pl -verbose Unknown option: e Unknown option: r Unknown option: b Unknown option: o Unknown option: s Unknown option: e usage >perl 806754.pl --verb Unknown option: verb usage >perl 806754.pl -V Unknown option: V usage >perl 806754.pl --Verbose Unknown option: Verbose usage

6 of 6 tests successful.

Replies are listed 'Best First'.
Re^2: How can I have both short and long options with Getopt::Long?
by almut (Canon) on Nov 12, 2009 at 16:16 UTC

    --v still fails to fail  (as requested, "if there are two dashes then only the full 'verbose' should be accepted") — as with the other variants already suggested.

      Missed that. There's no way around it because Getopt::Long has no way of knowing "v" shouldn't be considered a full option name. Honestly, that shouldn't be an issue.
Re^2: How can I have both short and long options with Getopt::Long?
by Anonymous Monk on Apr 16, 2014 at 12:46 UTC
    >perl 806754.pl --v you code is working in above case (it's need to show error, but that is not happening here)