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?


In reply to [Solved] Printing a 2D array into constant-sized columns by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.