Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(jeffa) Re: Multiplication table

by jeffa (Bishop)
on Aug 02, 2003 at 14:35 UTC ( [id://280283]=note: print w/replies, xml ) Need Help??


in reply to Multiplication table

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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://280283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found