Subject: | Change of behavior in Getopt::Long |
Date: | Tue, 12 Nov 2013 15:15:57 -0700 |
To: | bug-Getopt-Long [...] rt.cpan.org |
From: | Kevin Zwack <kzwack [...] gmail.com> |
Hello,
Thank you for supporting Getopt::Long, I use it in all my program. I
recently upgraded from a 2.3x version to 2.42 and noticed a slight change
of behavior, which I think the following little program can demonstrate.
#!/usr/bin/perl
use Getopt::Long qw(:config pass_through);
my $foo;
GetOptions('foo=s' => \$foo);
print join ", ", @ARGV;
In one application, I use the "pass_through" option with several Perl
modules in which each module processes its own options, and leaving the
rest for the others.
In the past, foo='' (that's two single quotes or null) would be slurped up
by foo=s... Now in 2.42 foo=s only slurps up the option if it is given a
non-null value such as foo='bar'.
./foo.pl -foo='' -bar
Getopt::Long 2.42 called from package "main".
argv: (-foo= -bar)
autoabbrev=1,bundling=0,getopt_compat=1,gnu_compat=0,order=1,
ignorecase=1,requested_version=0,passthrough=1,genprefix="(--|-|\+)",longprefix="(--)".
=> link "foo" to SCALAR(0x5703e4)
=> $opctl{foo} = ARRAY(0x65cecc) ["s","foo","<undef>",$,1,1]
=> arg "-foo="
=> find "-foo="
=> split "-"+"foo="
=> option "foo", optarg = ""
=> 1 hits (foo) with "foo" out of 1
=> found ["s","foo","<undef>",$,1,1] for "foo"
=> saving "-foo=" (not an option, may permute)
=> arg "-bar"
=> find "-bar"
=> split "-"+"bar"
=> 0 hits () with "bar" out of 1
=> saving "-bar" (not an option, may permute)
=> restoring "-foo=" "-bar"
-foo=, -bar
I decided this is a bug in my application, and made a change to the effect
'foo:s' (change = to : ) and it now works correctly for me.
If this is now the intended behavior of Getopt::Long, I'm okay with that
and see the logic in it (an equals sign really means there must be a
supplied string). Or perhaps it is an unexpected side-effect to some other
change. I just wanted to mention it as an FYI. I don't know where to get
older versions of Getopt::Long (I use the CPAN shell), so I cannot find
exactly at which version the change may have occurred.
Thanks,
Kevin Zwack
CYGWIN_NT-6.1 USDEND-KZwack 1.7.25(0.270/5/3) 2013-08-31 20:37 x86_64 Cygwin
(Windows 7 x64 w/ Cygwin)
pelr -v
This is perl 5, version 14, subversion 2 (v5.14.2) built for
MSWin32-x86-multi-thread
(Strawberry Perl)