andyford has asked for the wisdom of the Perl Monks concerning the following question:

Anyone know of a DBM-type module that implements a round robin structure, i.e. throw away the oldest row as new ones are added?
Kinda like rrdtool, only don't need consolidation and it will work with arbitrary rows of "stuff" instead of single numbers.
Is it something that's easy to do by hand with some other system?

andyford
or non-Perl: Andy Ford

Replies are listed 'Best First'.
Re: Round Robin DBM?
by shmem (Chancellor) on Sep 19, 2006 at 23:10 UTC
    If there was a module, I probably wouldn't want to use it. The task at hand can be coded with a few lines of perl, and a module that covers all or most possible uses of a ring buffer would just be overkill.

    All you need is an array of defined length - then handle it with push and shift. If entries are added arbitrarily, use splice.

    If you want to tie that array to a database - use tie. See perltie and Tie::Array.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Round Robin DBM?
by Arunbear (Prior) on Sep 19, 2006 at 22:29 UTC
      These are amazingly perfect. Thanks, I would have never found these on my own.

      andyford
      or non-Perl: Andy Ford

Re: Round Robin DBM?
by GrandFather (Saint) on Sep 19, 2006 at 22:03 UTC

    In some circles that would be known as a ring buffer.


    DWIM is Perl's answer to Gödel