is there a way to advance the file handle so it doesn't re-read the next line
If you know the line lengths in the file are uniform then using seek allows you to randomly access file contents as opposed to sequential access hence a position in a file can be reached directly without having to go through the file from the beginning, however, that needs you to know the file content details and to account for the effect of buffering (check the above link). Seek has the syntax 'seek FILEHANDLE, POSITION, WHENCE;' WHENCE specifies the interpretation of POSITION, it can be either 0,1, or 2.

Also reading a file via IO modules provides support for seek through the IO::Seekable interface

use IO::File; use IO::Seekable; $|++; # turn off buffering... my $handle = new IO::File; $handle->open("<FileHello.txt")or die("error $!\n"); $handle->seek(12,0); while(<$handle>){ print; } $handle->close;


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: advancing in file read by biohisham
in thread advancing in file read by cammac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.