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>&nbsp;</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>&nbsp;</td> <td>&nbsp;</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

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.