SPUG: Pretty-Printing Nested Hashes?

Adam Monsen haircut at gmail.com
Mon Sep 19 17:13:40 PDT 2005

On 9/19/05, Michael Wallendahl <mwallend at spikus.com> wrote:
> Hello,
> I'm wondering if anyone has a suggestions on a good algorithm to
> 'pretty-print' a nested hash in tabular form?

You could pick a max length for each column, then use substr to
truncate anything longer than your desired max length. Other than
that, the algorithm you've implemented looks fine. Any fancy solutions
(like using a custom tied hash that sorts keys or keeps track of the
longest value, or something like that) would have to do the same work
as what you wrote, but would probably be less straightforward to
maintain. But, of course, YMMV, TMTOWTDI, etc.


Adam Monsen

More information about the spug-list mailing list