develooper Front page | perl.perl5.porters | Postings from February 2011

[perl #84490] Getopt::Long POD patch (code example and typo fix)

From:
gene sullivan
Date:
February 21, 2011 00:38
Subject:
[perl #84490] Getopt::Long POD patch (code example and typo fix)
Message ID:
rt-3.6.HEAD-24085-1298230674-712.84490-75-0@perl.org
# New Ticket Created by  gene sullivan 
# Please include the string:  [perl #84490]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=84490 >


This is a bug report for perl from gsullivan@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.12.2.
 
I have included a patch for the Getopt::Long POD (version 2.38).
The patch includes:
   1. A additional small code example
   2. A minor typo fix
 
In its "User-defined subroutines to handle options" section, the Getopt::Long
POD text mentions that the option name and value are available inside a
subroutine.  I thought a small code example would be helpful in demonstrating
how to access this useful information.  I have been using Getopt::Long
for a while now, and I just learned about this feature a few days ago
on PerlMonks from user Eliya.
 
I also noticed a small typo in that section of the POD:
    change "arguments" to "argument".
 
Here is the patch:
 
--- Long.pm.2.38 Sun Feb 20 13:58:41 2011
+++ Long.pm Sun Feb 20 14:12:04 2011
@@ -1766,7 +1766,7 @@
 argument is the name of the option. (Actually, it is an object that
 stringifies to the name of the option.) For a scalar or array destination,
 the second argument is the value to be stored. For a hash destination,
-the second arguments is the key to the hash, and the third argument
+the second argument is the key to the hash, and the third argument
 the value to be stored. It is up to the subroutine to store the value,
 or do whatever it thinks is appropriate.
 
@@ -1796,6 +1796,15 @@
 option name so this change should not introduce compatibility
 problems.
 
+Here is an example of how to access the option name and value from within
+a subroutine:
+
+    GetOptions ('time=i' => \&parsetime);
+    sub parsetime {
+        my ($opt_name, $opt_value) = @_;    
+        print "Option name is $opt_name and value is $opt_value\n";
+    }
+
 =head2 Options with multiple names
 
 Often it is user friendly to supply alternate mnemonic names for
 
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.12.2:
Configured by gecko at Thu Dec  9 04:00:41 2010.
Summary of my perl5 (revision 5 version 12 subversion 2) configuration:
   
  Platform:
    osname=MSWin32, osvers=5.2, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8168', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl5-12-2\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl512.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl5-12-2\lib\CORE"  -machine:x86'
Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    1fd8fa4 Add Wolfram Humann to AUTHORS
    f120055 make string-append on win32 100 times faster
    a2a8d15 Define _USE_32BIT_TIME_T for VC6 and VC7
    007cfe1 Don't pretend to support really old VC++ compilers
    6d8f7c9 Get rid of obsolete PerlCRT.dll support
    d956618 Make Term::ReadLine::findConsole fall back to STDIN if /dev/tty can't be opened
    321e50c Escape patch strings before embedding them in patchlevel.h
---
@INC for perl 5.12.2:
    C:/Perl5-12-2/site/lib
    C:/Perl5-12-2/lib
    .
---
Environment for perl 5.12.2:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Perl5-12-2\site\bin;C:\Perl5-12-2\bin;C:\Perl\site\bin;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\QuickTime\QTSystem\
    PERL_BADLANG (unset)
    SHELL (unset)



      


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