I think it would make your life easier if you would massage your date into a more appropriate form on the Perl side, instead of fighting with slices of linear arrays within the template.

Here's a simplified example showing a possible data structure:

#!/usr/bin/perl -w use strict; use Template; my $templ = q{ <table> <tr> <td>date</td> [% FOREACH realname IN Users %] <td>[% realname %]</td> [% END %] </tr> [% FOREACH row IN Dates %] <tr> <td>[% row.Day %]</td> [% FOREACH date IN row.EndDates %] <td>[% date %]</td> [% END %] </tr> [% END %] </table> }; my $vars = { Users => [qw(user1 user2 user3 user4 user5)], Dates => [ { Day => 'day1', EndDates => [qw(dl1 dl2 dl3 dl4 dl5)], }, { Day => 'day2', EndDates => [qw(dl6 dl7 dl8 dl9 dl10)], }, { Day => 'day3', EndDates => [qw(dl11 dl12 dl13 dl14 dl15)], }, ], }; my $tt = Template->new(); $tt->process(\$templ, $vars) or die $tt->error();

Output:

date user1 user2 user3 user4 user5
day1 dl1 dl2 dl3 dl4 dl5
day2 dl6 dl7 dl8 dl9 dl10
day3 dl11 dl12 dl13 dl14 dl15

In reply to Re^4: How to skip certain values in a foreach loop by Anonyrnous Monk
in thread How to skip certain values in a foreach loop by Frederic_S

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.