in reply to Implementing a parsing rule in a huge data file

Update: simplified a bit more.

A bit simpler than the other suggestions, and it works.

use strict; while( <DATA> ) { if( /^1$/ ) { my $n = 0; ++$n while defined( $_ = <DATA> ) and /^\n$/; $n = 1 if /_____ 2/; print '1', "\n" x $n; } print; } __DATA__ 1 b 1 _____ 2

There are two keys to the simplicity.

  1. You don't have to only read lines at the top of the loop.
  2. There is no need to buffer the newlines, just count them.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Implementing a parsing rule in a huge data file
by thezip (Vicar) on Dec 08, 2006 at 16:39 UTC

    I like this solution -- fewer parts to maintain and easier to look at six months down the road.

    Thanks!

    Where do you want *them* to go today?