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

perlfaq6 example is wrong: pull out lines between two patterns #8553

Closed
p5pRT opened this issue Aug 5, 2006 · 5 comments
Closed

perlfaq6 example is wrong: pull out lines between two patterns #8553

p5pRT opened this issue Aug 5, 2006 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 5, 2006

Migrated from rt.perl.org#40084 (status was 'resolved')

Searchable as RT40084$

@p5pRT
Copy link
Author

p5pRT commented Aug 5, 2006

From @Corion

Created by Administrator@dawn

The example in perlfaq6 is wrong for the question "How can I pull
out lines between two patterns that are themselves on
different lines?"​:

  while (<>) {
  $in_header = 1 .. /^$/;
  $in_body = /^$/ .. eof();
  # now choose between them
  } continue {
  reset if eof(); # fix $.
  }

1) The comment '#fix $.' is wrong. C&lt;reset;&gt; doesn't touch $.
2) The line number does not get reset.
3) The matching does not stop at EOF and start fresh with
the next file, because C<reset;> doesn't reset the flipflop
operators. Most likely this example was using m?^$? previously
but was modified without rechecking.

I have no better suggestion to fix this than to use m??, even
though this makes this example an example of how to use two
arcana that are seldom used and/or shouldn't be used at all.

-max

Perl Info

Flags:
     category=core
     severity=low

Site configuration information for perl v5.8.5:

Configured by Administrator at Fri Aug  6 13:59:28 2004.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
   Platform:
     osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
     uname=''
     config_args='undef'
     hint=recommended, useposix=true, d_sigaction=undef
     usethreads=undef use5005threads=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  -DPERL_IMPLICIT_CONTEXT 
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
     optimize='-MD -Zi -DNDEBUG -O1',
     cppflags='-DWIN32'
     ccversion='', gccversion='', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
     d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
     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:\perl\5.8.5\lib\CORE"  -machine:x86'
     libpth="C:\Programme\Microsoft Visual C++ Toolkit 2003\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 wsock32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.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 wsock32.lib mpr.lib winmm.lib 
version.lib odbc32.lib odbccp32.lib msvcrt.lib
     libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
     gnulibc_version='undef'
   Dynamic Linking:
     dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf  -libpath:"c:\perl\5.8.5\lib\CORE"  -machine:x86'

Locally applied patches:



@INC for perl v5.8.5:
     c:/perl/5.8.5/lib
     c:/perl/site/5.8.5/lib
     .


Environment for perl v5.8.5:
     HOME (unset)
     LANG (unset)
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=C:\Programme\Microsoft Visual C++ Toolkit 
2003\bin;C:\Programme\Microsoft Visual Studio .NET 
2003\Vc7\bin;C:\WINNT\Microsoft.NET\Framework\v1.1.4322;C:\Programme\Microsoft 
IntelliType 
Pro\;C:\texmf\miktex\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;c:\perl\5.8.5\bin;C:\Programme\Microsoft 
SDK\Bin\.;C:\Programme\Microsoft SDK\Bin\WinNT\.;C:\Programme\Microsoft 
SDK\Bin\.;C:\Programme\Microsoft SDK\Bin\WinNT\.;C:\Programme\Microsoft 
Visual C++ Toolkit 2003\bin;C:\Programme\Subversion\bin;c:\perl\5.8.5\bin
     PERL_BADLANG (unset)
     SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Aug 17, 2006

From rick@bort.ca

On Sat, Aug 05, 2006 at 02​:57​:48PM -0700, Max Maischein wrote​:

The example in perlfaq6 is wrong for the question "How can I pull
out lines between two patterns that are themselves on
different lines?"​:

 while \(\<>\) \{
     $in\_header =   1  \.\. /^$/;
     $in\_body   = /^$/ \.\. eof\(\);
\# now choose between them
 \} continue \{
reset if eof\(\);        \# fix $\.
 \}

1) The comment '#fix $.' is wrong. C&lt;reset;&gt; doesn't touch $.
2) The line number does not get reset.
3) The matching does not stop at EOF and start fresh with
the next file, because C<reset;> doesn't reset the flipflop
operators. Most likely this example was using m?^$? previously
but was modified without rechecking.

I have no better suggestion to fix this than to use m??, even
though this makes this example an example of how to use two
arcana that are seldom used and/or shouldn't be used at all.

Maybe the following? I'm guessing the example is meant to deal with
maildir-style mailboxes?

  while (<>) {
  $in_header = 1 .. /^$/;
  $in_body = /^$/ .. eof;
  # now choose between them
  } continue {
  $. = 0 if eof; # reset $.
  }

The eof() in the original isn't right either because it will only be
true for the last file read. To test each file in @​ARGV you need to use
eof, without parentheses.

--
Rick Delaney
rick@​bort.ca

@p5pRT
Copy link
Author

p5pRT commented Aug 17, 2006

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

@p5pRT
Copy link
Author

p5pRT commented Sep 13, 2006

From @rgarcia

On 11/08/06, Rick Delaney <rick@​bort.ca> wrote​:

Maybe the following? I'm guessing the example is meant to deal with
maildir-style mailboxes?

 while \(\<>\) \{
     $in\_header =   1  \.\. /^$/;
     $in\_body   = /^$/ \.\. eof;
     \# now choose between them
 \} continue \{
     $\. = 0 if eof;         \# reset $\.
 \}

The eof() in the original isn't right either because it will only be
true for the last file read. To test each file in @​ARGV you need to use
eof, without parentheses.

I changed perlfaq6 accordingly in the perlfaq svn repository (revision 7831).

@p5pRT
Copy link
Author

p5pRT commented May 12, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

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