- LICENSE AND COPYRIGHT
Array::FIFO - A Simple limitable FIFO array, with sum and average methods
my $ar = Array::FIFO->new( limit => 12 ); $ar->add( 20 ); $ar->add( 18 ); $ar->add( 22 ); say $ar->average;
Array::FIFO is meant to be a simple limitable array, for storing data in a FIFO manner; with an optional limit to how large the array can get. When the limit is reached, the oldest value is returned by
add when new values are added.
It's intent is for numeric values (i.e. current load of a system), but it should work for other data types if you're not in need of the calculation methods.
average methods return the current sum and average of the data as you would expect. It does this on once, then caches the result until the array changes.
Numeric value of how large the array is allowed to get. When it reaches limit, every item added causes the oldest item to be removed.
If no value is passed, there is no max size.
$ar->add( 99 );
You can add any type of item to the array; if it's not a number it will be treated as a value of 0 when when calculating sum() and average().
Returns the oldest element in the array.
Remove the oldest item on the array.
Reference directly the fifo array.
How many elements are in the array.
The maximum size the array is allowed to be.
The sum of all numeric elements in the array.
The average of all numeric elements in the array.
dburke at addictmud.org
If you encounter any bugs, or have feature requests, please create an issue on github. https://github.com/dwburke/perl-Array-FIFO/issues