blib/lib/Perlmazing/Perlmazing/columnize.pm untested

filter: Statementstmt 0.0% 0 / 16 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 CC 4 SCAR 28.0
CC
4
Cov
0%
main
20.0
BEGIN
2.0
CRAP 16.4
1 use Perlmazing qw(croak is_integer ceil);
2  
3 sub main {
4 my $columns = shift;
5 croak 'Usage: columnize($total_columns, @array) - where $total_columns must be an integer greater than 0' unless is_integer $columns and $columns > 0;
6 my @array = @_;
7 return unless @array;
8 my $group_size = ceil @array / $columns;
9 my @result;
10 for my $group (0..$group_size - 1) {
11 for my $column (0..$columns - 1) {
12 my $index = $column * $group_size + $group;
13 if (exists $array[$index]) {
14 push @{$result[$group]}, $array[$index];
15 }
16 }
17 }
18 @result;
19 }