Just another way to do it using
HTML::ElementTable. For CGI applications you will want to stick with the
CGI approach noted above, for efficiency. This approach is nice for static generation and tweaking individual cells. Also note you might find
HTML::Table of interest.
#!/usr/bin/perl -w
use HTML::ElementTable;
use HTML::AsSubs;
use POSIX qw(ceil);
print "Content-type:text/html\n\n";
print "<html><head><title>Build Table.pl</title></head>\n";
print "<body>\n";
$total_cells = 517;
$display_cells = $total_cells / 15;
$row_count = 10;
$col_count = ceil($display_cells / $row_count);
$table = HTML::ElementTable->new(maxrow => $row_count-1,
maxcol => $col_count-1);
$table->attr('cellpadding' => 4);
$table->attr('border' => 1);
$table->blank_fill(1);
# counters
$row_inc = 1;
$col_label = 1;
$nav_count = 15;
$nav_inc = 15;
for my $r (0 .. $row_count-1) {
for my $c (0 .. $col_count-1) {
$table->cell($r,$c)->push_content(
a({href => "mypage.html?nav=$nav_count"}, $col_label))
if $nav_count < $total_cells;
$col_label+=10;
$nav_count+=150;
}
$row_inc++;
$col_label = $row_inc;
$nav_inc+=15;
$nav_count = $nav_inc;
}
# Here you could tweak the cells of $table
print $table->as_HTML;
print "</body></html>\n";
Have fun,
Matt
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.