Closed p5pRT closed 20 years ago
It seems that the Getopt::Long configuration parameter\, "getopt_compat" which should affect the way options starting with the character '+' doesn't actually make it ignore +something command line arguments.
Here's some code to demonstrate what I'm talking about:
---- snip ---- use Getopt::Long;
Getopt::Long::Configure("no_getopt_compat");
my $please_foo;
GetOptions('foo' => \$please_foo);
print "foo = ${please_foo}\n"; ---- snip ----
And the result:
(liff@emi)~> perl getopt-test.pl +foo foo = 1
Setting the POSIXLY_CORRECT environment variable does result in correct behaviour though:
(liff@emi)~> POSIXLY_CORRECT=whynot perl getopt-test.pl +foo foo =
I did look into Long.pm too and it seems that setting no_getopt_compat doesn't change the option prefix variable from (--|-|\\+) to (--|-) like I believe it should. However\, simply setting prefix to (--|-) whenever the value of getopt_compat changes doesn't seem very polite either since the prefix is also configurable.
So\, perhaps adding something like this below line 821 in Long.pm would fix the problem(?): $genprefix = "(--|-)" if ( !$getopt_compat && $genprefix eq "(--|-|\\+)" );
Hope this helps..
On Thu\, Mar 08\, 2001 at 01:15:53AM +0200\, liff@iki.fi wrote:
It seems that the Getopt::Long configuration parameter\, "getopt_compat" which should affect the way options starting with the character '+' doesn't actually make it ignore +something command line arguments.
Here's some code to demonstrate what I'm talking about:
---- snip ---- use Getopt::Long;
Getopt::Long::Configure("no_getopt_compat");
my $please_foo;
GetOptions('foo' => \$please_foo);
print "foo = ${please_foo}\n"; ---- snip ----
And the result:
(liff@emi)~> perl getopt-test.pl +foo foo = 1
I think this may actually be a documentation error.
The documentation for Getopt::Long describes two different behaviors for getopt_compat:
If configuration option getopt_compat is set (see section CONFIGURATION OPTIONS)\, options that start with "+" or "-" may also include their arguments\, e.g. "+foo=bar". This is for compatiblity with older implementations of the GNU "getopt" routine.
[...]
getopt_compat Allow '+' to start options. Default is set unless environment variable POSIXLY_CORRECT has been set\, in which case getopt_compat is reset.
It appears that the first description is accurate\, while the second description is more prominent in the documentation.
Ronald
[Quoting Ronald J Kimball\, on March 7 2001\, 22:51\, in "Re: [ID 20010307.006"]
It seems that the Getopt::Long configuration parameter\, "getopt_compat" which should affect the way options starting with the character '+' doesn't actually make it ignore +something command line arguments.
Currently\, getopt_compat only controls whether it is allowed to use "-foo=bar". Whether a leading "+" is allowed is controlleb by the environment variable POSIXLY_CORRECT. This is not according to the documentation.
So what would be best to change: docs or code? And why?
-- Johan
Migrated from rt.perl.org#5990 (status was 'resolved')
Searchable as RT5990$