I'm looking for some code that does the same sort of formatting done by the Unix 'ls' command, which looks something like this:

B Digest Filter MIME SDBM_File Time util ByteLoader DynaLoader GDBM_File NDBM_File Safe Unicode Cwd Encode I18N ODBM_File Socket XS DB_File Errno IO Opcode Storable attrs Data Fcntl IPC POSIX Sys re Devel File List PerlIO Thread threads

The salient features are a) to read entries in sorted order you read down one column before moving over to the next; b) columns are left-justified; c) columns are as wide as they need to be to fit the largest entry within them; d) as many columns as possible are used; e) all but the last column have the same number of entries, and the last column has no more than the other columns.

This is intended for the list of available commands in a help system roughly modelled on gdb's. I haven't written any code to do this yet, because I imagine someone has already done so.

I did find one implementation (thanks ysth) in the implementataion of ls in the Perl Power Tools project, but that uses a more simplistic approach that makes all columns as wide as the widest column, rather than making each column only as wide as it needs to be.

Any suggestions gratefully received.

Hugo


In reply to 'ls -C' column style by hv

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.