in reply to Re^5: How to skip certain values in a foreach loop
in thread How to skip certain values in a foreach loop
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: How to skip certain values in a foreach loop
by Anonymous Monk on Dec 30, 2010 at 12:16 UTC |