NAME
Array::LIFO - Last-in, First-out array
VERSION
version 0.0202
SYNOPSIS
use Array::LIFO;
my $ar = Array::LIFO->new( max_size => 12 );
$ar->add(20);
$ar->add(18);
$ar->add(22);
print $ar->size, "\n";
print $ar->average, "\n";
print $ar->sum, "\n";
print $ar->peek, "\n";
$ar->remove;
print "@{ $ar->stack }\n";
DESCRIPTION
An Array::LIFO
allows the declaration of an array with last-in, first-out operation. That is, a "stack."
NAME
Array::LIFO - Last-in, First-out array
METHODS
new
$x = Array::LIFO->new;
$x = Array::LIFO->new( max_size => $m );
- max_size (optional)
-
Numeric value of how large the array is allowed to get. When it reaches max_size, new items are not added.
If no value is passed, there is no max size.
add
$ar->add($x);
You can add any type of item to the array. If the element is not a number it will be ignored by the sum()
and average()
calculations.
remove
$ar->remove;
Remove the last item on the array.
size
$size = $ar->size;
How many elements are in the array.
max_size
$max = $ar->max_size;
The maximum size the array is allow to be.
sum
$sum = $ar->sum;
The sum of all numeric elements in the array.
average
$avg = $ar->average;
The average of all numeric elements in the array.
peek
$last = $ar->peek;
$element = $ar->peek($index);
Return an element of the array given by the index argument. If no index is provided, the last element added to the stack is returned.
SEE ALSO
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.