Front page | perl.perl5.porters |
Postings from January 2012
[perl #108712] documentation bug in perlfaq5 (To delete lines, ...)
Thread Previous
From:
sdziegie @ stronglg . demon . co . uk
Date:
January 21, 2012 09:24
Subject:
[perl #108712] documentation bug in perlfaq5 (To delete lines, ...)
Message ID:
rt-3.6.HEAD-14510-1327162446-1015.108712-75-0@perl.org
# New Ticket Created by sdziegie@stronglg.demon.co.uk
# Please include the string: [perl #108712]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=108712 >
This is a bug report for perl from sdziegie@stronglg.demon.co.uk,
generated with the help of perlbug 1.39 running under perl 5.12.1.
Hello,
I think that I have found a bug in the perlfaq5 documentation, namely the
text:
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
bye
keep dis
bye
EOT
# 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
---
Flags:
category=docs
severity=low
---
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:
Platform:
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
Compiler:
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/libc-2.11.2.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.11.2'
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:
/usr/lib/perl5/site_perl/5.12.1/i586-linux-thread-multi
/usr/lib/perl5/site_perl/5.12.1
/usr/lib/perl5/vendor_perl/5.12.1/i586-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.12.1
/usr/lib/perl5/5.12.1/i586-linux-thread-multi
/usr/lib/perl5/5.12.1
.
---
Environment for perl 5.12.1:
HOME=/home/sdziegie
LANG=en_GB.UTF-8
LANGUAGE (unset)
LC_COLLATE=POSIX
LD_LIBRARY_PATH=/usr/local/lib:/opt/experimental/lib:/usr/X11R6/lib:
LOGDIR (unset)
PATH=/home/sdziegie/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/gnome/bin:/usr/lib/qt3/bin:/usr/lib/festival:/usr/local/apache-maven-2.0.9/bin:/usr/lib/festival:/usr/local/apache-maven-2.0.9/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread Previous