I would use a recursive subroutine to walk the tree and collect the output as you go. Maybe something like this will help you (depth traversal):

use HTML::Template; my $thingy = [ { name => 'foo', id => 1, children => [ { name => 'bar', id => 2, children => [ { name => 'baz', id => 3, }, { name => 'qux', id => 4, }, ], }, { name => 'ducks', id => 5, }, ], }, { name => 'last', id => 6, }, ]; our $tmpl = HTML::Template->new( filehandle => \*DATA, die_on_bad_params => 0, ); our $output; our $tab_loop = []; recurse($thingy); print $output; sub recurse { my $thingy = shift; for (@$thingy) { $tmpl->param(tab_loop => $tab_loop, %$_); $output .= $tmpl->output; push @$tab_loop, { tab => "\t" }; recurse($_->{children}) if ref $_->{children}; pop @$tab_loop; } } __DATA__ <tmpl_loop tab_loop><tmpl_var tab></tmpl_loop><tmpl_var id> - <tmpl_va +r name>

I'd be tempted to attack this problem with Template instead.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: list of list and HTML::Template by jeffa
in thread list of list and HTML::Template by InfiniteLoop

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.