Subject: | Integer options, zero is ignored in favor of default |
# echo 'use Data::Dumper; use Getopt::Simple; $opt = new Getopt::Simple;
$opt->getOptions({"purge" => { type=>"=i", default => 1, order => 1 }},
"usage..", 1,1); $opt->dumpOptions(); die Dumper($opt->{switch})' >
/tmp/zero.pl
# perl /tmp/zero.pl -p 4321
Option Value
-purge 4321
$VAR1 = {
'purge' => 4321
};
# perl /tmp/zero.pl -p 0
Option Value
-purge 1
$VAR1 = {
'purge' => 1
};
# perl /tmp/zero.pl -p '0'
Option Value
-purge 1
$VAR1 = {
'purge' => 1
};
# echo 'use Data::Dumper; use Getopt::Long; my $opts = {};
GetOptions("purge=i" => \$opts->{purge}); die Dumper($opts);' >
/tmp/zero_long.pl
# perl /tmp/zero_long.pl -p 5678
$VAR1 = {
'purge' => 5678
};
# perl /tmp/zero_long.pl -p 0
$VAR1 = {
'purge' => 0
};
# perl /tmp/zero_long.pl -p '0'
$VAR1 = {
'purge' => 0
};
# perl -le 'use Data::Dumper; foreach (qw(Getopt::Simple Getopt::Long))
{ print "$_"; eval "use $_;"; print eval "\$".$_."::VERSION;"; }'
Getopt::Simple
1.48
Getopt::Long
2.35
Subject: | accept_zero_as_integer.patch |
--- Simple.pm.orig 2008-02-16 06:37:58.000000000 -0600
+++ Simple.pm 2008-02-16 06:38:06.000000000 -0600
@@ -114,6 +114,6 @@
}
else
{
- $$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} if (! $$self{'switch'}{$_});
+ $$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} unless (defined $$self{'switch'}{$_});
}
}