My main point was that it's much easier to transform your data with Perl, than to cope with data structures that are suboptimal for the template in question on the Template Toolkit side.  Perl is a very powerful general purpose programming language, while the Template Toolkit mini language is special purpose and (deliberately) limited in features — otherwise you might as well directly embed Perl code into the HTML template... (as some other templating systems do, btw).

In other words, to transform a linear array of deadlines (as you seem to get from your db query) into a more appropriate structure, you could do something like this:

#!/usr/bin/perl -w use strict; my @dls = 'dl01'..'dl20'; # what you start out with my $nusers = 5; my $vars; for (my $i = 0; $i < @dls; $i += $nusers) { push @{ $vars->{Dates} }, { EndDates => [ @dls[$i..$i+$nusers-1] ] }; } use Data::Dumper; print Dumper $vars; __END__ $VAR1 = { 'Dates' => [ { 'EndDates' => [ 'dl01', 'dl02', 'dl03', 'dl04', 'dl05' ] }, { 'EndDates' => [ 'dl06', 'dl07', 'dl08', 'dl09', 'dl10' ] }, { 'EndDates' => [ 'dl11', 'dl12', 'dl13', 'dl14', 'dl15' ] }, { 'EndDates' => [ 'dl16', 'dl17', 'dl18', 'dl19', 'dl20' ] } ] };

This is just an example, which you'd have to tailor to your circumstances, like adding the Day entries, etc.


In reply to Re^6: 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.