Subject: | Getopt::Long Passes Options to Non-Option Handler when pass_through is Enabled |
Date: | Sat, 25 Jan 2014 11:39:13 -0500 |
To: | bug-Getopt-Long [...] rt.cpan.org |
From: | David Narvaez <david.narvaez [...] computer.org> |
Consider the following minimal example
use strict;
use Getopt::Long qw(GetOptions :config pass_through);
use Data::Dumper;
my $foo = 0;
my %options;
print Dumper(@ARGV);
print "-------\n";
GetOptions(
'foo=i' => \$foo,
'<>' => sub {
my $nonopt = shift;
print "Nonopt: ${nonopt}\n";
}
);
print "${foo}\n";
print "-------\n";
print Dumper(@ARGV);
And the following output:
$ perl getopttest.pl --foo 5 --bar 2 test
$VAR1 = '--foo';
$VAR2 = '5';
$VAR3 = '--bar';
$VAR4 = '2';
$VAR5 = 'test';
-------
Nonopt: --bar
Nonopt: 2
Nonopt: test
5
-------
The option --bar is being passed as a non-option and is being removed
from @ARGV, which is against the documentation in two ways:
documentation says the <> handler is for non-options (like test in the
example) and documentation says that, with pass_through, unknown
options are left in the array.
My module version is 2.42, my Perl version is perl 5, version 16,
subversion 3 (v5.16.3).
David E. Narvaez