Subject: | Parsing of type 'o' not correct for multiple values |
E:\>type test.pl
#!perl -w
use strict;
use warnings;
use Getopt::Long;
my @opts;
GetOptions('opt=o@{,}' => \@opts) or die;
print join(',', @opts), "\n";
E:>perl test.pl --opt 1 2 0x3
1,2,0x3 # Should be 1,2,3
E:\>perl test.pl --opt 0x1 2 0x3
1,2,0x3 # Should be 1,2,3 - note first value correct
FindOption() correctly applies ord() to the first arg in the list, but
GetOptionsFromArray() doesn't apply ord() to subsequent args. I think
the follow patch (against 2.38_02) is what's needed.
--- Long.pm.orig Tue Apr 19 15:59:12 2011
+++ Long.pm Tue Apr 19 16:02:45 2011
@@ -662,6 +662,7 @@
if ( ValidValue($ctl, $argv->[0], 1, $argend,
$prefix) ) {
$arg = shift(@$argv);
$arg =~ tr/_//d if $ctl->[CTL_TYPE] =~
/^[iIo]$/;
+ $arg = ($ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/) ?
oct($arg) : 0+$arg;
($key,$arg) = $arg =~ /^([^=]+)=(.*)/
if $ctl->[CTL_DEST] == CTL_DEST_HASH;
next;
@@ -679,6 +680,7 @@
if ( @$argv && ValidValue($ctl, $argv->[0], 0, $argend,
$prefix) ) {
$arg = shift(@$argv);
$arg =~ tr/_//d if $ctl->[CTL_TYPE] =~ /^[iIo]$/;
+ $arg = ($ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/) ?
oct($arg) : 0+$arg;
($key,$arg) = $arg =~ /^([^=]+)=(.*)/
if $ctl->[CTL_DEST] == CTL_DEST_HASH;
next;
Subject: | test.pl |
#!perl -w
use strict;
use warnings;
use Getopt::Long;
my @opts;
GetOptions('opt=o@{,}' => \@opts) or die;
print join(',', @opts), "\n";
Subject: | patch |
Message body not shown because it is not plain text.