in reply to How to Seperate Presentation from Implementation with HTML::Template
The number of columns is adjusted by changing cols = 3 to whatever you'd like. That code prints out: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;
<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>
|
|---|