vlad.belogrudov has asked for the wisdom of the Perl Monks concerning the following question:

Good time! I have puzzled myself with rather easy problem: there is a list of hosts, each host has several configurations, and each configuration runs several tests. The resulting structure reminds the following:
my %results; $results{$host}{$config}{$test} = 'OK'; # or 'FAILED'
I would like to format them into a table
--------------------------------- hosts | configs | tests | results --------------------------------- host1 | conf1 | test1 | res1 | |---------------- | | test2 | res2 |-------------------------- | conf2 | test3 | res3 ... --------------------------------- host2 | ...
I could not figure out 'format' for such a table (all my attempts with multilines etc. brought nothing) and wonder if it's worth to look into CPAN for related functionality instead. Thanks for any ideas

Replies are listed 'Best First'.
Re: multilevel report
by marto (Cardinal) on Apr 13, 2011 at 10:02 UTC

    "I would like to format them into a table --------------------------------- hosts | configs | tests | results --------------------------------- host1........."

    Welcome to the Monastery. When you previewed your post it would have looked as bad as it currently does. Formatting advice is displayed when posting, please don't ignore it:

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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! —
Re: multilevel report
by chrestomanci (Priest) on Apr 13, 2011 at 13:48 UTC

    I had a similar programming problem a few years ago, where I wanted to generate a table where some cells would span several rows or columns, and it was hard to predict in advance how many rows/columns a cell would span.

    The solution I adopted was first to generate the table in memory as a simple 2 dimensional array of hashes, Then once the data had been turned into a table, I had another function that compared and merged neighbouring identical cells. Finally the table was rendered in it's final form. I was rendering to HTML. From your problem description, it looks like you need to render to plain text, so Text::Table looks suitable.

Re: multilevel report
by raybies (Chaplain) on Apr 13, 2011 at 12:35 UTC

    wonder if it's worth to look into CPAN for related functionality instead

    CPAN's always worth looking at. Go for it and Good luck! --Ray

      I agree with checking to see what's available on CPAN. Doing a quick search, here's two possible candidates: