Skip Menu |

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

Report information
The Basics
Id: 81129
Status: new
Priority: 0/
Queue: Getopt-Tabular

People
Owner: Nobody in particular
Requestors: Matthew.Blythe [...] amd.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Inadvertant ambiguous option
Date: Tue, 13 Nov 2012 00:08:43 +0000
To: "bug-Getopt-Tabular [...] rt.cpan.org" <bug-Getopt-Tabular [...] rt.cpan.org>
From: "Blythe, Matthew" <Matthew.Blythe [...] amd.com>
In certain cases, Getopt::Tabular will say that an option is ambiguous even when there is an exact match in the options table. Code: use Getopt::Tabular; use strict; my $numberA = 1; my $numberB = 0; my $dash_n = 0; my @argtbl = ( ["-numberA", "const", 0, \$numberA, "set the foo option"], ["-numberB", "const", 0, \$numberB, "set the bar option"], ["-n", "const", 1, \$dash_n], ); &GetOptions (\@argtbl, \@ARGV); When this code is run with the "-n" option, it will complain: Show quoted text
>./testcode.pl -n
ambiguous option: -n I fixed this bug by modifying the match_abbreviation function as follows: sub match_abbreviation { my ($s, $words, $err_format) = @_; my ($match, $ambiguous); my $word; foreach $word (@$words) { # If $s is a prefix of $word, it's at least an approximate match, # so try to do better next unless ($s eq substr ($word, 0, length ($s))); # We have an exact match, so return it now return $word if ($s eq $word); # We have an approx. match, and already had one before if($match){ $ambiguous = 1; } $match = $word; } if ($ambiguous) { &SetError ("bad_option", sprintf ("$err_format", "ambiguous", $s)); return 0; } &SetError ("bad_option", sprintf ("$err_format", "unknown", $s)) if !$match; $match; } Thanks, Matt