in reply to Reading nth line from a file

Here is another simple way.
my @arrvar = <FH>; map { if ($arrvar[$_] =~ /you have to read the fourth line/) { print "$arrvar[$_+4]"; } elsif ($arrvar[$_] =~ /you have to read the second line/) { print "$arrvar[$_+2]"; } }0..$#arrvar;

Replies are listed 'Best First'.
Re^2: Reading nth line from a file
by perlthirst (Scribe) on Dec 19, 2008 at 06:44 UTC

    Thanks for your reply.

    But reading the whole file into an array may not be efficient. If the file size is too large, it will take so much memory i think.