develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #108712] documentation bug in perlfaq5 (To delete lines, ...)

Thread Previous
sdziegie @ stronglg . demon . co . uk
January 21, 2012 09:24
[perl #108712] documentation bug in perlfaq5 (To delete lines, ...)
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #108712]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.12.1.


I think that I have found a bug in the perlfaq5 documentation, namely the

To delete lines, only print the ones that you want.

        perl -ni -e 'print unless /d/' inFile.txt

                ... or ...

        perl -pi -e 'next unless /d/' inFile.txt

I think that the first method using -ni should read:

        perl -ni -e 'print if /d/' inFile.txt

I do not think that the second method can ever work and should be removed 
from the documentation altogether. Reading the 3rd edition of the Camel
Book it states that the -p switch has an implied:

    continue {
        print or die "-p destination: $!\n";

at the end. I believe that the 'next' can never bypass this continue block and
hence the example will always print every line.

Here is how I tested this out:

cat > inFile.txt.orig << EOT
This should stay
this goes
as should this
keep dis

# Method 1 as per perlfaq5 (I believe the documentation is wrong)
cp inFile.txt.orig inFile.txt; perl -ni -e 'print unless /d/' inFile.txt; cat inFile.txt

# Proposed documentation fix for Method 1 (see above)
cp inFile.txt.orig inFile.txt; perl -ni -e 'print if /d/' inFile.txt; cat inFile.txt

# Method 2 as per perlfaq5 (I believe that this should be struck from the
# documentation altogether as it cannot delete anything)
cp inFile.txt.orig inFile.txt; perl -pi -e 'unless /d/' inFile.txt; cat inFile.txt
This perlbug was built using Perl 5.12.1 - Fri May  6 13:30:46 UTC 2011
It is being executed now by  Perl 5.12.1 - Fri May  6 13:25:31 UTC 2011.

Site configuration information for perl 5.12.1:

Configured by abuild at Fri May  6 13:25:31 UTC 2011.

Summary of my perl5 (revision 5 version 12 subversion 1) configuration:
    osname=linux, osvers=2.6.32, archname=i586-linux-thread-multi
    uname='linux build34 2.6.32 #1 smp 2011-02-21 10:34:10 +0100 i686 athlon i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.5.0 20100604 [gcc-4_5-branch revision 160292]', 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 =' -fstack-protector'
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.12.1/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe'

Locally applied patches:

@INC for perl 5.12.1:

Environment for perl 5.12.1:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About