"Dude," that's not even close to the question. The format function only sets up static format. If you don't know the sizes of your columns ahead of time, you're (mostly) stuck. Even perl6's formats are still largely stuck in the same mindset, despite being much more flexible. The OP is asking if there is anything out there that will determine how many columns are needed, and automagically set up a nice table. See the 'ls' command on unix for an example. Even 'dir' on Windows, with the /w flag, is close.

For the most part, I've just made do with Text::Table. But it is an interesting problem. I would actually try using Text::Table, feeding it the screen width (which you can get with Term::Screen), and just keep adding columns until things don't fit. But that would definitely be slower than a more direct approach.

If the OP is really interested, you might be able to find the source to the ls command and reimplement that algorithm in Perl. The implementation side probably will be easier in perl than C, it'll be the deciphering of the ls code that will be the hard part ;-)


In reply to Re^2: Text Columns by Tanktalus
in thread Text Columns by geoffeg

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.