in reply to Parse a block of text

Another approach, not necessarily better than the others:

use warnings; use strict; my $START = qr{ \A Info [ ] I [ ] Want }xms; my $STOP = qr{ \A Start [ ] of [ ] Info [ ] I [ ] don't }xms; while (<DATA>) { if (/$START/ .. /$STOP/ xor /$STOP/) { print; } } __DATA__ asdfsdfds asdfasdf blah blah blah Info I Want I want this line And this line And this line this is the last line i want Start of Info I don't want blah blah blah blah blah

Output:

Info I Want I want this line And this line And this line this is the last line i want

Replies are listed 'Best First'.
Re^2: Parse a block of text
by Anonymous Monk on Jul 07, 2008 at 20:46 UTC
    while (<DATA>) { # logic crystal clear here next unless /$START/ .. /$STOP/; # next if /$START/; # exclude line with START pattern next if /$STOP/; # exclude line with STOP pattern print; }
Re^2: Parse a block of text
by Anonymous Monk on Jul 07, 2008 at 20:17 UTC
    On second thought...

    This solution fails if there is a stop-line not balanced by a start-line. A better solution (or at least one that doesn't have a subtle potential bug) is:

    use warnings; use strict; my $START = qr{ \A Info [ ] I [ ] Want }xms; my $STOP = qr{ \A Start [ ] of [ ] Info [ ] I [ ] don't }xms; while (<DATA>) { # if (/$START/ .. /$STOP/ xor /$STOP/) { # print; # } if (/$START/ .. /$STOP/ and not /$STOP/) { print; } } __DATA__ asdfsdfds asdfasdf blah blah blah Info I Want I want this line And this line And this line this is the last line i want Start of Info I don't want blah blah blah blah blah Start of Info I don't want blah blah blah blah blah
    <p Output: <p
    Info I Want I want this line And this line And this line this is the last line i want