I'm struggling trying to populate an HTML::Template using a two dimensional array, which contains the results of a database query. I've tried many permutations of the following code. I either get an infinite loop, or template variable does not exist error. Is there something obviously wrong? Thanks in advance for your input.
sub table_data { my $self = shift; my @outer_loop; for (my $row = 0; $row <= @{$self->{selection}}; $row++) { my %hash; $hash{table_data_begin_row} = q{<fo:table-row>}; my @inner_loop; for (my $col = 0; $col <= @{$self->{selectionAttr}}; $col++) { my %hash; $hash{table_data} = $self->{selection}[$row][$col]; push @inner_loop, \%hash; } $hash{table_data_close_row} = q{</fo:table-row>}; $hash{table_data} = \@inner_loop; push @outer_loop, \%hash; } $self->{tmpl_obj}->param(table_data_loop => \@outer_loop); }
TEMPLATE:
<fo:table-body> <TMPL_LOOP NAME=table_data_loop> <TMPL_VAR NAME=table_data_begin_loop> <TMPL_LOOP NAME=table_data> <fo:table-cell> <fo:block border-right-width="0.5pt" text-align="center" vertical-al +ign="middle"> <TMPL_VAR NAME=table_data> </fo:block> </fo:table-cell> </TMPL_LOOP> <TMPL_VAR NAME=table_data_close_loop> </TMPL_LOOP> </fo:table-body>

In reply to Help with nested loop in HTML::Template by mhearse

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.