, , - . - , . , List:: Util, List:: MoreUtils . . , , , .
use strict;
use warnings;
use Test::More;
use List::Util qw(max);
my @Things = qw(
AAA23
AB1D1
A1BC
AAB212
);
sub rotate {
my @rows = @_;
my $maxlength = max map { length $_ } @rows;
my @columns;
for my $row (@rows) {
my @chars = split //, $row;
for my $colnum (1..$maxlength) {
my $idx = $colnum - 1;
$columns[$idx] .= $chars[$idx] || ' ';
}
}
return @columns;
}
sub print_columns {
my @columns = @_;
for my $idx (0..$#columns) {
printf "Column %d: %s\n", $idx + 1, $columns[$idx];
}
}
sub test_rotate {
is_deeply [rotate @_], [
"AAAA",
"AB1A",
"A1BB",
"2DC2",
"31 1",
" 2",
];
}
test_rotate(@Things);
print_columns(@Things);
done_testing;