Here is how i would do it. Don't print out the values as
you calculate them - instead, store them in a 2-D array:
sub get_table {
my $max = $_[0] - 1;
my @table;
for my $y (0..$max) {
for my $x (0..$max) {
$table[$y][$x] = ($x + 1) * ($y + 1);
}
}
return @table;
}
so that you can use existing CPAN modules to render them.
For example, via
Text::Table:
use Text::Table;
my $max = shift || 12;
my @table = get_table($max);
my $text_table = Text::Table->new(1..$max);
$text_table->load(@table);
print $text_table->body;
or an XHTML table via
DBIx::XHTML_Table:
use DBIx::XHTML_Table;
my $max = shift || 12;
print DBIx::XHTML_Table
->new([get_table($max)],[])
->output({no_head=>1})
;
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
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.