in reply to FILE operation in PERL

You have two choices. Either you can save the whole file in an array, with one line per array element, in which case you can just refer to $array[30], or else on the way by you can use tell to find out where you are right before you read a line, then use seek to go back there.

Replies are listed 'Best First'.
Re: Re: FILE operation in PERL
by diotalevi (Canon) on Jul 19, 2003 at 06:20 UTC

    Hers' a sample implementation

    my @line_offsets; push @line_offsets, tell *FOO; while (my $line = <FOO>) { push @line_offsets, tell *FOO; if ( foobar() ) { seek *FOO, $line_offsets[29]; } }