in reply to How to Seperate Presentation from Implementation with HTML::Template

The CSS solution is good and is a solution that I would advocate.

But sometimes it is hard to make CSS fit your case and sometimes you really do want to use tables (ie for non-changing grid layouts). In these cases - you can use a template to do everything - if the template language has enough mini-language to it. The following is a sample from the Template Toolkit 2 dialect (even though I show CGI::Ex::Template - it would also work with Template::Toolkit).
use CGI::Ex::Template; my @a = qw(one two three four five six seven eight); my $temp = q{ [%~ cols = 3 %] [%~ rows = a.size DIV cols %] [%~ IF a.size % cols ; rows = rows + 1 ; END -%] <table> [%- FOR i IN [1 .. rows] %] <tr> [%- FOR j IN [1 .. cols] %] [%~ k = (i - 1) * cols + (j - 1) %] <td>[% a.$k %]</td> [%- END %] </tr> [%- END %] </table> }; CGI::Ex::Template->new->process(\$temp, {a => \@a}) || die $CGI::Ex::T +emplate::error;
The number of columns is adjusted by changing cols = 3 to whatever you'd like. That code prints out:
<table> <tr> <td>one</td> <td>two</td> <td>three</td> </tr> <tr> <td>four</td> <td>five</td> <td>six</td> </tr> <tr> <td>seven</td> <td>eight</td> <td></td> </tr> </table>


my @a=qw(random brilliant braindead); print $a[rand(@a)];