The Template Toolkit can do this as well using one of the built-in plugins:
#!/usr/bin/perl use strict; use Template; my @raw_data = ( '1|seans.gif|Sean Shrum', '2|steves.gif|Steve Shrum', '3|dianas.gif|Diana Shrum', '4|marthas.gif|Martha Shrum' ); my @data = map { [ split '\|', $_ ] } @raw_data; my $template = Template->new(); $template->process( \*DATA, { data => \@data, column_num => 3 } ) || die $template->error(); __DATA__ [%- USE table( data, rows = column_num ) -%] [% FOREACH col = table.cols -%] <tr> [%- FOREACH item = col -%] [%- IF item %] <td><img src="[% item.1 %]"><br> [% item.0 %] [% item.2 %]</td> [%- ELSE %] <td> </td> [%- END %] [%- END %] </tr> [% END -%]
Which produces:
<tr> <td><img src="seans.gif"><br> 1 Sean Shrum</td> <td><img src="steves.gif"><br> 2 Steve Shrum</td> <td><img src="dianas.gif"><br> 3 Diana Shrum</td> </tr> <tr> <td><img src="marthas.gif"><br> 4 Martha Shrum</td> <td> </td> <td> </td> </tr>
The table plugin takes a little getting used to, but it's extremely handy.
Chris
M-x auto-bs-mode
In reply to Re: Grouping multiple records in a row...templating ?
by lachoy
in thread Grouping multiple records in a row...templating ?
by S_Shrum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |