Why bother with re-writing a file every time? Look at, say, BerkeleyDB, which maintains an efficient key/value pair database.

What you're talking about is being able to re-order existing records. The best strategy for this might be to use a single BerkeleyDB database, and re-define the keys from time to time to re-define the order of the posts. So in the value of each record, you maintain the time of the post (so you can get latest-first), and the ID or quality ranking of the poster, as well as the messsage. You generate your keys to the most significant few (say, 4) bytes supply a serial number that gives the number of re-order passes. This way, as you re-order records, they go to the end of the database, and you can then delete them from the beginning.

Each time you re-order, you do this:

increment the re-order sequence number For each record that was not re-ordered this time through, read the record re-compute the key based on the age and poster ID write the new key/value pair (with the new re-order number) delete the old key/value pair

The beauty of this is that BerkeleyDB will efficiently reclaim the file space with a minimum of work. When you have new messages, you just give them a key that will allow you to find them before the previous messages (cursors in BerkeleyDB can go forwards (DB_NEXT) or backwards (DB_PREV)).


In reply to Re: Message Board Mangling by bikeNomad
in thread Message Board Mangling by achiles

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.