Databases are put together in the order they come in, right? If so, I won't need a timestamp, right?

The only safe way to retrieve the last N records inserted is to tag each record with a monotonically increasing sequence number that you can query against later. Your code does that (though your method of maintaining the sequence number needs some flock() protection).

But for doing something like "delete everything older than 24 hours", you'll also need to associate a timestamp with each record. If you were storing your data in a relational table, you'd probably have a column to hold the insert time. But you're using DBM, which complicates things somewhat. You could do something like prepending a timestamp to each value, splitting the timestamp off when necessary. Then, a periodic "delete everything older than 24 hours" scan can work its way through the DBM by sorted key value, splitting off the timestamp from each record and deleting those records that have expired.


In reply to Re: Retrieve last elements of a DB by dws
in thread Retrieve last elements of a DB by sulfericacid

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.