Subject: | optional option value broken with |
Optional option values don't (no longer?) seem to work if gnu_compat is in effect.
The documentation says that the argument following an option which takes an optional value will only be used if it "does not look like a value command line option itself". The docs also say that if an optional value is not provided, then '' will be supplied for string options (0 for numerics).
But with gnu_getopt enabled, none of this works: If a value _is_ supplied, it is not used but is left in @ARGV even though the following arg is a different valid argument. If a value is NOT supplied, the arg is not set to '' but is left undefined, i.e., the argument is just swallowed with no effect whatever.
I'm pretty sure this is a regression, as some existing scripts stopped working recently because of this.
#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;
use Getopt::Long;
@ARGV = (qw(-a avalue -b extra1 extra2 ));
my ($a, $b);
#Getopt::Long::Configure("gnu_getopt");
Getopt::Long::Configure(qw(gnu_compat));
my $r = GetOptions(
"a:s" => \$a,
"b" => \$b,
);
die unless $r;
print Data::Dumper->Dump([$a, $b, \@ARGV], ['a', 'b', 'argv']);
die "ERROR(?) \$a is undef" unless defined($a); # dies here