Queue::Base - Simple OO style queue implementation.
version 2.1_04
use Queue::Base; # construction my $queue = new Queue::Base; # or my $queue = new Queue::Base(\@elements); # add a new element to the queue $queue->add($element); # remove the next element from the queue if (! $queue->empty) { my $element = $queue->remove; } # or $element = $queue->remove; if (defined $element) { # do some processing here } # add/remove more than just one element $queue->add($elem1, $elem2 ...) # and @elements = $queue->remove(5);
The Queue::Base is a simple implementation for queue structures using an OO interface. Provides basic functionality: nothing less - nothing more.
Creates a new empty queue.
ELEMENTS is an array reference with elements the queue to be initialized with.
Adds the LIST OF ELEMENTS to the end of the queue.
In scalar context it returns the first element from the queue.
In array context it attempts to return NUMBER_OF_ELEMENTS requested; when NUMBER_OF_ELEMENTS is not given, it defaults to 1.
Returns an array with all the elements in the queue, and clears the queue.
Returns the size of the queue.
Returns whether the queue is empty, which means its size is 0.
Removes all elements from the queue.
The module works only with scalar values. If you want to use more complex structures (and there's a big change you want that) please use references, which in perl5 are basically scalars.
Alexei Znamensky <russoz@cpan.org>
This software is copyright (c) 2011 by Farkas Arpad.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Queue::Base, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Queue::Base
CPAN shell
perl -MCPAN -e shell install Queue::Base
For more information on module installation, please visit the detailed CPAN module installation guide.