Skip Menu |

This queue is for tickets about the Getopt-Long CPAN distribution.

Report information
The Basics
Id: 127584
Status: resolved
Priority: 0/
Queue: Getopt-Long

People
Owner: jv [...] cpan.org
Requestors: cxwembedded [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.50
Fixed in: (no value)



Subject: Optional hash-valued option warns when key is missing, even though the key is not required
Minimal test case of Getopt::Long v2.50 on perl 5.26.1, Cygwin x64: $ perl -MGetopt::Long -E 'my %o; GetOptions(\%o, "v:s%")' -- -v Use of uninitialized value $key in anonymous hash ({}) at .../perl-5.26.1/lib/site_perl/5.26.1/Getopt/Long.pm line 659. The specification `:s%`, permitting optional hash values, is rather strange. However, suppose someone typed it instead of `=s%` by accident! I would expect $o{v} == {} in that case, without the "uninitialized-value" message. If you have opportunity, would you be willing to look at this? Thank you!
The intention of `:s%` is to assign keys without values. In your example the following is legal: -v xx it adds (or modifies) key 'xx' with an empty value. Would it be written `s=%`, then the above would give an error that a value is required for key 'xx'. Using `-v` without key is not valid, but this situation is not correctly dealt with and yields a perl warning instead of a Getopt::Long error.
The next version of Getopt::Long will issue a neat warning: "Option v requires an argument"