Could I do something better or does exist some module which does that for me?
#!/usr/bin/perl
use 5.012;
use warnings;
my @list = '01' .. '95';
my $col = 9;
my $row = int( ( $#list + $col ) / $col );
my $d = @list % $col;
my @arr;
my $i = 0;
for ( 0 .. $col ) {
$i = 1 if $d and $_ >= $d;
$arr[$_] = [splice( @list, 0, $row - $i )];
}
for my $e ( 0 .. $row - 1 ) {
my @list;
for my $c ( 0 .. $col - 1 ) {
next if $d and $e == $row-1 and $c >= $d;
push @list, $arr[$c][$e];
}
say "@list";
}
output:
01 12 23 34 45 56 66 76 86
02 13 24 35 46 57 67 77 87
03 14 25 36 47 58 68 78 88
04 15 26 37 48 59 69 79 89
05 16 27 38 49 60 70 80 90
06 17 28 39 50 61 71 81 91
07 18 29 40 51 62 72 82 92
08 19 30 41 52 63 73 83 93
09 20 31 42 53 64 74 84 94
10 21 32 43 54 65 75 85 95
11 22 33 44 55
output: