A modification of my solution below would be to change the way the data is split up and put each row into a hash with an array of recipients

my @cols = split(/[,\s]+/); my %row; $row{quarantined_id} = pop @cols; for my $key ( qw( month day time category sender ) ) { $row{$key} = shift @cols; } $row{recipients} = \@cols; push @{$data{rows}}, \%row; ... [% FOR row=rows %] <tr> <td>[% row.month %] [% row.day %] [% row.t +ime %]</td> <td>[% row.category %]</td> <td>[% row.sender %]</td> <td>[% FOR recipient=row.recipients %][% r +ecipient %]<br />[% END %]</td> <td>[% row.quarantined_id %]</td> </tr> [% END %]

Full example

#!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use CGI::Carp 'fatalsToBrowser'; # use only for testing use Template; my $cgi = new CGI; $cgi->header( -charset => 'utf-8' ); $ENV{"PATH"} = "/usr/sbin:/usr/bin:/sbin:/bin"; my %data; while(<DATA>) { chomp; my @cols = split(/[,\s]+/); my %row; $row{quarantined_id} = pop @cols; for my $key ( qw( month day time category sender ) ) { $row{$key} = shift @cols; } $row{recipients} = \@cols; push @{$data{rows}}, \%row; } close FILE; my $tt = new Template; my $template = q( <!DOCTYPE html> <html> <head> <title>PM 1215287</title> </head> <body onload="parent.adjustMyFrameHeight();"> <div id='wrapper'> <table> <thead> <tr> <th>Time</th> <th>Category</th> <th>Sender</th> <th>Recipients</th> <th>Quarantined-ID</th> </tr> </thead> <tbody> [% FOR row=rows %] <tr> <td>[% row.month %] [% row.day %] [% row.t +ime %]</td> <td>[% row.category %]</td> <td>[% row.sender %]</td> <td>[% FOR recipient=row.recipients %][% r +ecipient %]<br />[% END %]</td> <td>[% row.quarantined_id %]</td> </tr> [% END %] </tbody> </table> </div> <style> body { background-color : #95B8DB; } #wrapper { min-height:500px; display:block; } table, tr, th, td { border : 1px solid grey; } </style> </body> </html> ); $tt->process( \$template, \%data ) or die $tt->error; __DATA__ May 3 15:58:17 SPAM sender@domain.com peter.w@recipient.com spam-Lub +_LynRmcvj.gz May 3 15:58:24 SPAM sender@domain1.com coev074@recipient1.com spam-g +SCAdAuMpiD0.gz May 3 15:59:27 BANNED sender@domain2.com nadia.meli@grecipient2.com +banned-BpF8aM7FM48B May 3 16:00:29 SPAM sender@domain.com sascha_ste@recipient.com spam- +6fFrrzUjgvug.gz May 3 16:01:48 INFECTED sender@domain3.com philipp_me@recipient.com +virus-SZLvi-VO4IIv May 4 16:02:28 SPAM sender@domain.com caro.grill@recipient3.com spam +-saYzvikxOfVL.gz May 4 16:02:45 SPAM sender@domain.com pellitter@recipient.com spam-8 +K649OHNlRQ2.gz May 4 16:03:14 SPAM sender@domain1.com anton.d@recipient.com spam-3r +pUGn3IcDnG.gz May 5 10:39:42 SPAM sender@domain1.com amil@recipient.com , dab@recip +ient.com , jay@recipient.com , sa@recipient.com , wid@recipient.com +spam-Nnlc4bqiNeQD.gz May 5 11:00:41 SPAM sender@domain.com amil@recipient.com , duminda@re +cipient.com , samindak@recipient.com , vajirak@recipient.com spam-gj +WpzbXc8o1q.gz May 6 01:07:04 SPAM sender@domain1.com amil@recipient.com , samindak@ +recipient.com spam-x-vwwUP5yfqJ.gz May 7 12:54:26 SPAM sender@domian.com amil@recipient.com spam-o6LPjf +Cnz211.gz

In reply to Re^3: INSERT file contents inside a table by rnewsham
in thread INSERT file contents inside a table by theravadamonk

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.