I'd be inclined to store the file offset of either the line or the line following the last match (using tell) then you can seek to the position in the file that you want to continue from having reached the end of the file.

The following code demonstrates the technique:

use strict; use warnings; my $lastFound = -1; # No match value $| = 1; /\ba\b/ and ($lastFound = tell DATA) while <DATA>; print "No match \n" and exit if $lastFound == -1; seek DATA, $lastFound, 0; print <DATA>; __DATA__ Hi, I've seen a few similar problems to this posted here recently but +none of them cover what I need to do and my Perl isn't strong enough yet for m +e to figure out how to do this. I'm parsing a number of text files (can ran +ge in size from 1K upto 100M) where the record size of each line is variable. I n +eed to find (or seek to ?) the last occurence of a pattern then apply some fu +rther parsing logic from that point on until the end of file. What I do now +(which doesn't cope with the problem) is:

Prints:

parsing logic from that point on until the end of file. What I do now +(which doesn't cope with the problem) is:

DWIM is Perl's answer to Gödel

In reply to Re: parse from last occurence of pattern match by GrandFather
in thread parse from last occurence of pattern match by Anonymous Monk

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.