Since you're sorting the file contents you must have enough memory to hold and sort the entire set of log files. If you can avoid sorting the data and holding the complete set of files in memory that would help with any future memory issues you might have. Perhaps read in enough to detect a change of timestamp and sort just on that slice if data. I'm assuming the log files are written with timestamps and more or less in sequence.

When the data is written to the DB there is presumably a timestamp field for the data in the DB. That could be used to search for the latest records already in the DB. The latest timestamp records could be deleted upon restart of the script and replaced from the logs to ensure a complete set of records for that timestamp. Subsequent timestamp data would simply come from subsequent log data. Either that or you've got to record how may records through the files you have processed. Perhaps the database updates could be used for that as well.

In reply to Re: file state management and recovery by Anonymous Monk
in thread file state management and recovery 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.