The simple answer is, don't use format, use HTML::Template or one of the other templating solutions available from CPAN. Consider:

use strict; use warnings; use HTML::Template; my $template = <<'TEMPLATE'; <table border="2"> <tr> <th>Job</th> <th>Status</th> <th>Start</th> <th>End</th> <th>Remark</th> </tr> <TMPL_LOOP NAME=rows> <tr><TMPL_LOOP NAME=row><td><TMPL_VAR NAME=a></td></TMPL_LOOP></tr> </TMPL_LOOP> TEMPLATE my @x; my @y; while(<DATA>){ if(/^AA/){ push @x, {row => [map {{a => $_}} split ',']}; }elsif(/^BB/){ push @y, {row => [map {{a => $_}} split ',']}; } } writeReport (\@x, "AA") if @x; writeReport (\@y, "BB") if @y; sub writeReport { my ($cat, $name) = @_; my $t = HTML::Template->new (scalarref => \$template); $t->param (rows => $cat); print $t->output(); } __DATA__ AA,data2,NORMAL,16/08/2008 16:00:31,52/08/2008 16:00:33, AA,data2,NORMAL,16/08/2008 16:00:31,52/08/2008 16:00:33, BB,data1,NORMAL,12/08/2008 16:00:31,12/08/2008 16:00:33, BB,data5,NORMAL,13/08/2008 16:00:31,20/08/2008 16:00:33, BB,data4,NORMAL,14/08/2008 16:00:31,32/08/2008 16:00:33, BB,data3,NORMAL,15/08/2008 16:00:31,42/08/2008 16:00:33, AA,data2,NORMAL,16/08/2008 16:00:31,52/08/2008 16:00:33, BB,data1,NORMAL,12/08/2008 16:00:31,12/08/2008 16:00:33,

Prints:

<table border="2"> <tr> <th>Job</th> <th>Status</th> <th>Start</th> <th>End</th> <th>Remark</th> </tr> <tr><td>AA</td><td>data2</td><td>NORMAL</td><td>16/08/2008 16:00:31</t +d><td>52/08/2008 16:00:33</td><td> </td></tr> <tr><td>AA</td><td>data2</td><td>NORMAL</td><td>16/08/2008 16:00:31</t +d><td>52/08/2008 16:00:33</td><td> </td></tr> <tr><td>AA</td><td>data2</td><td>NORMAL</td><td>16/08/2008 16:00:31</t +d><td>52/08/2008 16:00:33</td><td> </td></tr> <table border="2"> <tr> <th>Job</th> <th>Status</th> <th>Start</th> <th>End</th> <th>Remark</th> </tr> <tr><td>BB</td><td>data1</td><td>NORMAL</td><td>12/08/2008 16:00:31</t +d><td>12/08/2008 16:00:33</td><td> </td></tr> <tr><td>BB</td><td>data5</td><td>NORMAL</td><td>13/08/2008 16:00:31</t +d><td>20/08/2008 16:00:33</td><td> </td></tr> <tr><td>BB</td><td>data4</td><td>NORMAL</td><td>14/08/2008 16:00:31</t +d><td>32/08/2008 16:00:33</td><td> </td></tr> <tr><td>BB</td><td>data3</td><td>NORMAL</td><td>15/08/2008 16:00:31</t +d><td>42/08/2008 16:00:33</td><td> </td></tr> <tr><td>BB</td><td>data1</td><td>NORMAL</td><td>12/08/2008 16:00:31</t +d><td>12/08/2008 16:00:33</td><td> </td></tr>

Perl's payment curve coincides with its learning curve.

In reply to Re: how to re-use "Formats" by GrandFather
in thread how to re-use "Formats" by benlaw

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.