NAME
Array::Dissect - Convert an array into N-sized array of arrays.
SYNOPSIS
use Array::Dissect qw( :all );
@sample = ( 1 .. 10 );
$rowsize = 3;
reform( $rowsize, @sample );
=>
(
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ],
[ 10 ]
);
dissect( $rowsize, @sample );
=>
(
[ 1, 5, 9 ],
[ 2, 6, 10 ],
[ 3, 7 ],
[ 4, 8 ]
);
DESCRIPTION
This is intended as a much-improved replacement for Array::Reform. Given the current maintainer's apparent lack of interest in keeping this module up to date, it unfortunately, for now, exists separately.
Both these methods are designed to reformat a list into a list of lists. It is often used for formatting data into HTML tables, amongst other things.
The key difference between the two methods is that dissect()
takes elements from the start of the list provided and pushes them onto each of the sub-arrays sequentially, rather than simply dividing the list into discrete chunks. As a result dissect()
returns a list of lists where the first element of each sublist will be one of the first elements of the source list, and the last element will be one of the last. This behavior is much more useful when the input list is sorted.
With both methods the array to be reformed can be passed as an array or an array reference.
AUTHOR
Alex Bowley <kilinrax@cpan.org>, implementing improvements to Array::Reform suggested by Dave Cross <dave@dave.org.uk>.
SEE ALSO
Array::Reform.