Scalar::Array - Turns arrayrefs into iterators
use Scalar::Array; my $rr_ref = [ 1, 2, 3, 4, 5 ]; round_robin( $rr_ref ); print sa_length( $rr_ref ); # prints 5 print $rr_ref,"\n"; # prints 1 print $rr_ref,"\n"; # prints 2 print $rr_ref,"\n"; # prints 3 print $rr_ref,"\n"; # prints 4 print $rr_ref,"\n"; # prints 5 print $rr_ref,"\n"; # prints 1 print $rr_ref,"\n"; # prints 2 print $rr_ref,"\n"; # prints 3 ... my $s_ref = [ 1, 2, 3, 4, 5 ]; shrink( $s_ref ); print sa_length( $s_ref ); # prints 5 print $s_ref,"\n"; # prints 1 print $s_ref,"\n"; # prints 2 print $s_ref,"\n"; # prints 3 print $s_ref,"\n"; # prints 4 print $s_ref,"\n"; # prints 5 print $s_ref,"\n"; # undef print $s_ref,"\n"; # undef print $s_ref,"\n"; # undef
Scalar::Array will turn any arrayref into an iterator by simply using the arrayref itself. Only reading is currently implemented.
round_robin( $arrayref );
Turn the passed in arrayref into a round robin iterator. At each iteration, we shift off the next value and then push back on the other end. See SYNOPSIS for the example.
shrink( $arrayref );
Turn the passed in arrayref into a shrinking iterator. At each iteration, we shift off the next value, but don't push back on the other end. In other words, the arrayref will shrink on each read.
printf "Arrayref has %d items\n", sa_length( $arrayref );
Return the number of items in the arrayref.
This did seem like a good idea at the time. Now I'm not so sure.
Alfie John, <alfie@h4c.kr>
Copyright (C) 2010 by Alfie John
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
Unknown directive: =head
To install Scalar::Array, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scalar::Array
CPAN shell
perl -MCPAN -e shell install Scalar::Array
For more information on module installation, please visit the detailed CPAN module installation guide.