karlberry has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getopt::Long case matching last wins
by hippo (Archbishop) on May 28, 2023 at 15:21 UTC | |
by karlberry (Sexton) on May 29, 2023 at 21:08 UTC | |
by hippo (Archbishop) on May 30, 2023 at 14:28 UTC | |
by karlberry (Sexton) on May 30, 2023 at 21:26 UTC | |
by hv (Prior) on May 30, 2023 at 22:42 UTC | |
| |
|
Re: Getopt::Long case matching last wins
by sciurius (Beadle) on Jun 01, 2023 at 06:45 UTC |