Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: gnepp [...] deshaw.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 2.32
  • 2.32_01
Fixed in: (no value)



Subject: Incorrect handling of hash options without a value
% perl -MGetopt::Long -MData::Dumper -le ' my %defines; Getopt::Long::GetOptions("define=s", \%defines); print Dumper(\%defines); ' -- -define d $VAR1 = { 'd' => 1 }; Even though no value has been specified for the key 'd', the value has defaulted to 1. The culprit is at line 902, where the value defaults to 1 if it is not defined and there is no default. ($key, $arg) = ($arg =~ /^([^=]*)=(.*)$/s) ? ($1, $2) : ($arg, defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : 1); Patch: 902c902,909 < : ($arg, defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : 1); --- Show quoted text
> : ($arg, defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : undef); > if (! defined $arg) { > warn ("Value not supplied for key \"$key\" to hash option $opt\n"); > $error++; > # Push back. > unshift (@ARGV, $starter.$rest) if defined $rest; > return (1, undef); > }
I'm running: - Getopt-Long-2.32_01 (or 2.32) - perl v5.6.1 - SunOS ucas1.nyc.deshaw.com 5.8 Generic_108528-15 sun4u sparc Andrei Gnepp
From: gneppa [...] deshaw.com
[correct email address: gneppa@deshaw.com - Andrei Gnepp]
This was fixed in 2.32.