If all you want to do is dump the contents of a SELECT statement to an HTML table, use the Power of the CGI module. Instead of this (from
jeffa):
# html-table style
print "<table>\n";
foreach my $row (@$res) {
print "\t<tr>\n";
print map { "\t\t<td>$_</td>\n" } @$row;
print "\t</tr>\n";
}
print "</table>\n";
I would do this:
use CGI qw(:standard *table);
use CGI::Pretty; # For pretty-printed HTML
print start_table;
print Tr(td($_)) foreach @$rows;
print end_table;
Yes, it's just that easy. Of course, the more general solution is using some sort of templating scheme, but in general this is a pretty sweet way of outputting dynamic table data on the fly.
Gary Blackburn
Trained Killer
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.