If I save this as try.pl and run try.pl -v, the result is verbose=0, version=1.#!/usr/bin/env perl use strict; use warnings; use Getopt::Long; #use Getopt::Long qw(:config no_ignore_case); my $opt_verbose = 0; my $opt_version = 0; GetOptions( "verbose|v" => \$opt_verbose, "version|V" => \$opt_version, ) or die "getopt failed"; print "verbose=$opt_verbose, version=$opt_version\n";
I would have expected either for the exact case match to be preferred, or getopt to complain, per its documentation:
With "ignore_case", option specifications for options that only differ in case, e.g., "foo" and "Foo", will be flagged as duplicates.but apparently this does not happen for alternate names.
Workarounds are possible, such as the commented-out :config no_ignore_case, or switching the order of the option specifications. But it feels wrong that the result depends on the order given.
I don't expect the behavior to change after all these years, but maybe there is something to say in the doc. Or am I missing something already there that explains the behavior? It seems like this (v vs. V) would be such a common case that I doubt I'm discovering anything new here.
I tried with perl 5.36.1, also 5.24.0 (just an old version I had at hand), and (as expected) results were the same.
Thanks for any wisdom ... --karl
In reply to Getopt::Long case matching last wins by karlberry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |