http://www.perlmonks.org?node_id=865019


in reply to Read Some lines in Tera byte file

Unless you happen to know the position at which the 100th line starts, you'll have to read from the start of the file. You can stop reading any time, though.
for (1..100) { <$fh>; } for (1..100) { my $line = <$fh>; ... }

Replies are listed 'Best First'.
Re^2: Read Some lines in Tera byte file
by Anonymous Monk on Oct 13, 2010 at 06:50 UTC

    Thanks for reply

    Here ..

    for (1..100) { <$fh>; }

    we are reading from 1st line to 100th lines, then

    for (1..100) { my $line = <$fh>; ... }

    we are saving required to a variable i.e from position 100th line 200th line

    So unnecessary reading first 100 lines in the first code, is it possible directly read from 100th line?

      Already answered. Unless you happen to know the position at which the 100th line starts, you'll have to read from the start of the file. If you do, you can jump straight to that position using seek.

      No.

        because i said file is in tera bytes, so if my file reading position is nth (ex : 99999999) then it will be difficult to parse all lines and consuming time also.

        do we have function in perl like seek?

        because i said file is in tera bytes, so if my file reading position is nth (ex : 99999999) then it will be difficult to parse all lines and consuming time also.

        do we have function in perl like seek?