sashac88 has asked for the wisdom of the Perl Monks concerning the following question:

Hello again,Monks. Thanks for your help with my previous question. I have another issue.. While parsing text file I need to be able to locate (and to push to some array) all lines between two lines containing certain words. For example if I have a line with "START" then all lines untill a line with "STOP" will go to @lines. Thanks again...

Replies are listed 'Best First'.
Re: More text file parsing
by gellyfish (Monsignor) on Jun 28, 2004 at 14:05 UTC

    You could try something using the "flip-flop" operator:

    while(<DATA>) { if (/START/ .. /STOP/ ) { print unless /(START|STOP)/; } } __DATA__ 1 2 START 3 4 5 STOP 6 7

    /J\

      Thanks, gellyfish-you're a genius...
Re: More text file parsing
by neniro (Priest) on Jun 28, 2004 at 14:07 UTC
    Hello again!
    Last week there was an article on perl.com covering this case. I just copy and paste the example:
    while (<FILE>) { if (/START/ .. /STOP/) { push @lines, $_; } }
    neniro