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>
In reply to Re: how to re-use "Formats"
by GrandFather
in thread how to re-use "Formats"
by benlaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |