Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

Getopt::Long config parameter getopt_compat doesn't do what it should #3538

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#5990 (status was 'resolved')

Searchable as RT5990$

p5pRT commented 23 years ago

From @liff

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..

Perl Info ``` Flags: category=library severity=low Site configuration information for perl v5.6.0: Configured by bod at Tue Feb 27 03:27:16 EST 2001. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=linux, osvers=2.2.18, archname=i386-linux uname='linux duende 2.2.18 #1 thu dec 28 14:51:40 est 2000 i686 unknown ' config_args='-Dccflags=-DDEBIAN -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.0 -Darchlib=/usr/lib/perl/5.6.0 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.0 -Dsitearch=/usr/local/lib/perl/5.6.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3 -Dpager=/usr/bin/pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dlibperl=libperl.so.5.6.0 -Dd_dosuid -des' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='cc', optimize='-O2', gccversion=2.95.3 20010219 (prerelease) cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include' ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lc -lcrypt libc=/lib/libc-2.2.2.so, so=so, useshrplib=true, libperl=libperl.so.5.6.0 Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.6.0: /usr/local/lib/perl/5.6.0 /usr/local/share/perl/5.6.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.6.0 /usr/share/perl/5.6.0 /usr/lib/perl5/5.6/i386-linux /usr/lib/perl5/5.6 /usr/lib/perl5/5.005/i386-linux . Environment for perl v5.6.0: HOME=/home/liff LANG=finnish LANGUAGE (unset) LC_COLLATE=finnish LC_CTYPE=finnish LC_MESSAGES=C LC_MONETARY=finnish LC_NUMERIC=C LC_TIME=C LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin:/usr/local/sbin:/home/liff/bin:/usr/local/j2sdk1.3.0/bin:. PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 23 years ago

From @tamias

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

p5pRT commented 23 years ago

From @sciurius

[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