# Takes a number of columns then a list. Reformats the list into # an array of arrays, with the original elements sorted down by # columns, and any missing items missing off of the last column sub reformat_major_minor { my $dim = shift; my $row_size = int((@_+$dim - 1)/$dim); my @ret; foreach my $i (0..$#_) { $ret[$i%$row_size][$i/$row_size] = $_[$i]; } return @ret; }