Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation bug in perlfaq5 (To delete lines, ...) #11880

Closed
p5pRT opened this issue Jan 21, 2012 · 5 comments
Closed

documentation bug in perlfaq5 (To delete lines, ...) #11880

p5pRT opened this issue Jan 21, 2012 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 21, 2012

Migrated from rt.perl.org#108712 (status was 'rejected')

Searchable as RT108712$

@p5pRT
Copy link
Author

p5pRT commented Jan 21, 2012

From sdziegie@stronglg.demon.co.uk

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

@p5pRT
Copy link
Author

p5pRT commented Jan 21, 2012

From @cpansprout

Thank you for your report.

The perl faq are now maintained separately on CPAN, so I’m forwarding
your message to the CPAN ticket.

On Sat Jan 21 08​:14​:05 2012, sdziegie@​stronglg.demon.co.uk wrote​:

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&#8203;: $\!\\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

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jan 21, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 21, 2012

@cpansprout - Status changed from 'open' to 'rejected'

@p5pRT p5pRT closed this as completed Jan 21, 2012
@p5pRT
Copy link
Author

p5pRT commented Jan 22, 2012

From bug-perlfaq@rt.cpan.org

<URL​: https://rt.cpan.org/Ticket/Display.html?id=74215 >

Thanks for the report.

This has been fixed​:

https://github.com/perl-doc-
cats/perlfaq/commit/9be0139bb81d7ba9645b5366c17685f60ffb419d

Please submit pull requests against https://github.com/perl-doc-cats/perlfaq if you have
further feedback (which is really appreciated!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant