develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #41359] Getopt::Std Fails to Account For When you Tell it There Will be an Argument (:), But One Isn't Specified.

Thread Next
From:
David Yingling
Date:
August 5, 2013 23:25
Subject:
Re: [perl #41359] Getopt::Std Fails to Account For When you Tell it There Will be an Argument (:), But One Isn't Specified.
Message ID:
1375658871.27043.YahooMailNeo@web141106.mail.bf1.yahoo.com
I forgot all about this bug. I can't believe it was 6 years ago that I reported
it.

Your patch looks great, and clears up this issue, so you could probably also
close this ticket too.


Thanks,
Dave.


>________________________________
> From: James E Keenan via RT <perlbug-followup@perl.org>
>To: deeelwy@yahoo.com 
>Sent: Sunday, August 4, 2013 9:18 AM
>Subject: [perl #41359] Getopt::Std Fails to Account For When you Tell it There Will be an Argument (:), But One Isn't Specified.
> 
>
>On Sat Jan 27 04:45:18 2007, deeelwy@yahoo.com wrote:
>> This is a bug report for perl from deeelwy@yahoo.com;
>> generated with the help of perlbug 1.35 running under
>> perl v5.8.8.
>> 
>> 
>> -----------------------------------------------------------------
>> In Getopt::Std, there is a case that getopt() and
>> getopts() don't account for.  It occurs in getopt()
>> and in getopts() when you use the ':' to tell
>> getopts() what you want that preceding command line
>> option to take an argument.  The problem is that if
>> you specify the ':' in getopts() or just run getopt(),
>> neither of them handle the case where the program is
>> run without an argument for that command.  For
>> example:
>> 
>> ./test.pl -a
>> 
>> But it should be run as './test.pl -a foobar', because
>> you ran getopt() or used a ':' after a letter in your
>> call to getopts() (as in getopts(a:).  Below is a test
>> program that demonstrates this.
>> 
>> #Start getopts_bug.pl
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> #run like this to demo the bug: ./getopts_bug.pl -a
>> 
>> #Demonstrates a bug in Getopt::Std 1.05.
>> 
>> use Getopt::Std;
>> 
>> my %opts;
>> getopts('a:', \%opts);
>> 
>> map { print '$opts{', "$_", '} => ', $opts{$_}, "\n";
>> } keys %opts;
>> #End getopts_bug.pl
>> 
>> And here's one that shows the problem in getopt()
>> 
>> #Start getopt_bug.pl
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> #run like this to demo the bug: ./getopt_bug.pl -a
>> 
>> #Demonstrates a bug in Getopt::Std 1.05.
>> 
>> use Getopt::Std;
>> 
>> my %opts;
>> getopt('a', \%opts);
>> 
>> map { print '$opts{', "$_", '} => ', $opts{$_}, "\n";
>> } keys %opts;
>> #End getopt_bug.pl
>> 
>> If you run either of these programs without an
>> argument, it will print an error about an
>> uninitialized value, because it sets %opts{a}'s value
>> to undef, because $rest is undef, because their is no
>> argument to the test program, but it is expecting one.
>> 
>> 
>> Possible fixes:
>> 
>
>[snip]
>
>Discussion in this RT lapsed six years ago, perhaps because the
>follow-up posts were verbose and unfocused.  However, re-reading the
>ticket yesterday I realized that this is simply a documentation problem.
>Attached is a patch which remedies that and provides some additional
>unit tests which demonstrate what is now documented.
>
>I also took this opportunity to remove some tests from lib/Getopt/Std.t
>which were focused on Getopt::Long rather than Getopt::Std.  Per
>discussion on p5p last month, I have reworked these tests into a patch
>which I have submitted to Getopt::Long's bug queue: 
>https://rt.cpan.org/Public/Bug/Display.html?id=87581.
>
>Please review.
>
>Thank you very much.
>Jim Keenan
>> The easiest way to fix this is to just update
>> Getopt::Std's documentation to mention that if the
>> user of the program supplies an option without an
>> argument
>> that it will create the hash key/variable, but it's
>> value will be undef.
>> 
>> You could also just modify the code to set the hash
>> key/variable to 1 like the function already does for
>> boolean options, which would keep it consistent.
>> 
>> Please let me know if you fix this bug by changing
>> this module's behavior.
>> 
>> Thanks,
>> Dave
>> 
>> 
>> -----------------------------------------------------------------
>> ---
>> Flags:
>>     category=library
>>     severity=low
>> ---
>> Site configuration information for perl v5.8.8:
>> 
>> Configured by root at Fri Sep  1 23:30:41 CDT 2006.
>> 
>> Summary of my perl5 (revision 5 version 8 subversion
>> 8) configuration:
>>   Platform:
>>     osname=linux, osvers=2.4.33.3, archname=i486-linux
>>     uname='linux tree 2.4.33.3 #1 fri sep 1 01:48:52
>> cdt 2006 i686 athlon-4 i386 gnulinux '
>>     config_args='-de -Dprefix=/usr -Dcccdlflags=-fPIC
>> -Dinstallprefix=/usr -Doptimize=-O2 -march=i486
>> -mtune=i686 -Dinc_version_list=5.8.7 5.8.6 5.8.5 5.8.4
>> 5.8.3 5.8.2 5.8.1 5.8.0 -Darchname=i486-linux'
>>     hint=recommended, useposix=true,
>> d_sigaction=define
>>     usethreads=undef use5005threads=undef
>> useithreads=undef usemultiplicity=undef
>>     useperlio=define d_sfio=undef uselargefiles=define
>> usesocks=undef
>>     use64bitint=undef use64bitall=undef
>> uselongdouble=undef
>>     usemymalloc=n, bincompat5005=undef
>>   Compiler:
>>     cc='cc', ccflags ='-fno-strict-aliasing -pipe
>> -Wdeclaration-after-statement -I/usr/local/include
>> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
>>     optimize='-O2 -march=i486 -mtune=i686',
>>     cppflags='-fno-strict-aliasing -pipe
>> -Wdeclaration-after-statement -I/usr/local/include'
>>     ccversion='', gccversion='3.4.6', gccosandvers=''
>>     intsize=4, longsize=4, ptrsize=4, doublesize=8,
>> byteorder=1234
>>     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, prototype=define
>>   Linker and Libraries:
>>     ld='cc', ldflags =' -L/usr/local/lib'
>>     libpth=/usr/local/lib /lib /usr/lib
>>     libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
>>     perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
>>     libc=/lib/libc-2.3.6.so, so=so, useshrplib=false,
>> libperl=libperl.a
>>     gnulibc_version='2.3.6'
>>   Dynamic Linking:
>>     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef,
>> ccdlflags='-Wl,-E'
>>     cccdlflags='-fPIC', lddlflags='-shared
>> -L/usr/local/lib'
>> 
>> Locally applied patches:
>> 
>> 
>> ---
>> @INC for perl v5.8.8:
>>     /usr/lib/perl5/5.8.8/i486-linux
>>     /usr/lib/perl5/5.8.8
>>     /usr/lib/perl5/site_perl/5.8.8/i486-linux
>>     /usr/lib/perl5/site_perl/5.8.8
>>     /usr/lib/perl5/site_perl
>>     .
>> 
>> ---
>> Environment for perl v5.8.8:
>>     HOME=/root
>>     LANG=en_US
>>     LANGUAGE (unset)
>>     LC_COLLATE=C
>>     LD_LIBRARY_PATH (unset)
>>     LOGDIR (unset)
>> 
>> PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
>>     PERL_BADLANG (unset)
>>     SHELL (unset)
>> 
>> 
>> 
>> 
>>
>____________________________________________________________________________________
>> Want to start your own business?
>> Learn how on Yahoo! Small Business.
>> http://smallbusiness.yahoo.com/r-index
>
>
>
>
>
>

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About