in reply to read multi lines of a file in perl

You might also consider the flip-flop operator (see Flipin good, or a total flop?)

In your problem, the code would look something like:

while(<WORDLIST>) { if( /^process/ .. /end process/ ) { #recognize and skip first delimiter next if /^process/; #recognize and skip end delimiter next if /end process/; # do something with the middle. print; } }

This does have the advantage that it restarts if you hit another line starting with process. Obviously, you can also do something special with the start and end points.

Of course, if you don't need to know when the data starts and stops, you could just do

while(<WORDLIST>) { next if /^process/ or /^end process/; print; }
G. Wade

Replies are listed 'Best First'.
Re^2: read multi lines of a file in perl
by johngg (Canon) on Nov 05, 2008 at 16:02 UTC
    while(<WORDLIST>) { next if /^process/ or /^end process/; print; }

    You could consider combining the two matches into one (I would also use unless but I know that's not to everyone's taste).

    while( <WORDLIST> ) { print unless m{^(?:end\s)?process}; }

    I hope this is of interest.

    Cheers,

    JohnGG

      I probably would combine them (and use unless), but I was keeping it simple for early morning.<grin/>

      G. Wade