Hi all, I want a display_2d() function:
my @accounts = [
[ current => 1000 ],
[ savings => 2000 ],
[ other => 500 ],
];
display_2d(\@accounts);
# Should display:
current | 1000
savings | 2000
other | 500
I just wrote this code:
my $width_col = 8;
say join ' | ',
map {
# Give each column the same size
length($_) >= $width_col ?
$_ : $_ . " "x($width_col-length($_)) # add spaces
} @$_
for @rows;
and that felt unnecessary. Is there no CPAN module to do this? I'm pretty sure I'm not the only one needing this function.
I found Array::Columnize but it only displays one dimensional arrays. And flattening my array does not do the trick: everything ends up displayed in the wrong order. My solution with Array::Columnize ended up being almost as long as my solution without it. And allows for less flexibility (columns of different width, for example)
And Array::PrintCols makes my terminal bug for a minute and then display nothing.
Have you come across dispay_2d() anywhere on CPAN?