in reply to how to next line after the pattern in perl

One fairly straight-forward way to accomplish this task would be to simply read and print the next line in the file:

while (<FF>) { next unless /XXXX/; print scalar <FF>; }

Note that scalar is required to turn the print statement into scalar context. There are other ways of accomplishing this (e.g. appending an empty string), but this is simple and clear, at least to me. Note that this is fragile in that it would miss consecutive lines.

Replies are listed 'Best First'.
Re^2: how to next line after the pattern in perl
by cliff52 (Initiate) on Sep 22, 2010 at 12:27 UTC
    print scalar <FF>; ...worked for me - I needed the 2nd and 3rd lines after a match, so I used it twice.