Two Perl modules to handle table
I’ve been using Text::Table to output data onto screen and HTML::QuickTable into HTML file.
Text::Table can output data in table format with or without border which is composed of special characters. Here is an example:
use Text::Table;
my $sep = ' | ';
my $tb = Text::Table->new (\$sep, "Header", \$sep, "Index", \$sep);
my @data;
# ... fill @data
$tb->load (@data);
print $tb->rule('-', '+');
print $tb->title;
print $tb->rule('-', '+');
print $tb->body;
print $tb->rule('-', '+');
If you haven’t used this module, please try it to see what happens by filling dummy data into @data.
HTML::QuickTable is good at generating HTML table or entire HTML file from special data structure with little efforts. For example,
my @body;
while (<>) {
chomp;
my @row = split /,/, $_;
push @body, \@row;
}
my $qt = HTML::QuickTable->new;
print $qt->render (\@body);
But it gives less control on table layout than HTML::Table. I will not give example since help is written well and its usage is simple.
No comments yet.