Just to note, jeffa's and cfreak's similar solutions don't quite get the output that fireartist wanted. Specifically, they output a table which looks like this:
1 2 3 4 5 one two three four five ein zwei drei veir funf hana dool set net dasut yi er san si wu
However, what fireartist wanted was the following table:
1 one ein hana yi 2 two zwei dool er 3 three drei set san 4 four veir net si 5 five funf dasut wu
The desired HTML table output doesn't exactly match the structure of the @data array given in the code. In fact, luckily for fireartist, I don't think this "correct" output is possible to do efficiently with map().

With that said, the two solutions given by jeffa and cfreak are good starters for the most common HTML::Template situations. For everyone's sanity, it's usually best to keep the internal data structures consistent with the structure of the output table. In this case, the @data structure was symmetric to the output table, but not quite the same (perhaps because of other uses of @data in other code, or just unfamiliarity with HTML::Template). But in about 90% of situations, you want to make your internal data structured in the same way as the output. This way you get to use map(), and these two writeups are right on point for help in those situations (especially jeffa's suggestion to use Data::Dumper).

blokhead


In reply to Re: HTML table with HTML::Template and loop in a loop by blokhead
in thread HTML table with HTML::Template and loop in a loop by fireartist

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.