in reply to Getting next line after matched one

Here's a not-too-subtle solution:
my $flag = 0; while (<FILE>) { if ($flag) { $flag = 0; do_something($_); } if (/pattern/) { $flag = 1; next; } }
You need to consider the "special" case where you have two adjacent matching lines; the logic in this code may not suffice.

Replies are listed 'Best First'.
Re^2: Getting next line after matched one
by Solo (Deacon) on Dec 30, 2004 at 20:53 UTC
    I think it is as simple as reversing the tests and using an elsif in trammell's example to cover his "special" case...

    my $flag = 0; while( <FILE> ) { if ( /test/ ) { print; $flag = 1; } elsif ( $flag ) { print; $flag = 0; } }

    --Solo

    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.