Skip Menu |

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

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

People
Owner: jv [...] cpan.org
Requestors: robertmay [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 2.36
  • 2.36_01
  • 2.36_02
  • 2.37
  • 2.37_01
  • 2.37_02
  • 2.37_03
  • 2.38
  • 2.38_02
Fixed in: 2.39



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
Download patch
application/octet-stream 831b

Message body not shown because it is not plain text.

On Tue Apr 19 11:07:34 2011, ROBERTMAY wrote: Show quoted text
> 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.
s/ord/oct/g;