I was having a discussion on the CB about how to reduce overheads with very large files where the area of interest is just a small part of the file Found solution to some but not to all Case 1: Last 100 lines of the file(total 1000000 lines) is of interest. Solution use tail -100 on the file and process Also if end of line is what interests, File::ReadBackwards is there. But the problem which I could not find a solution to is this. I have a file which has 1000000 lines, but the area of interest is only after the certain regexp is found in the file. Standard solution
open FH, "file"; while (<FH>) { last if /regexp/; } while (<FH>) { do something; }
Now in the above case suppose I know the exact line number at which the regexp occurs, what I could do is a tail ($length - $line.no) and process the file. But if I dont then the above solution will not work. Also I was thinking If I know that the regexp occurs near the end of the file I cound use a readbackwards to get the file pointer till that regexp point and then start parsing the file. For that I need to know if there is a way to take the pointer to a certain line number. For example If I want while(<FH) {} to start parsing from line no 10000, how to do that?

In reply to Handling large files by tsk1979

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.