perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

Is there a CPAN module that automatically displays a DBI statement handle as an HTML table with little or no other configuration?
my $sth = $dbh->prepare(...); $sth->execute(...); format_sth_as_html_table($sth);

The idea is that it would use $sth->{NAME} for column headers and make sane choices for column alignment.

I actually have my own solution, but it would be nice to know what else is out there. I am also looking for good names for such a module.

Replies are listed 'Best First'.
Re: $sth to HTML <table>?
by CountZero (Bishop) on Mar 03, 2011 at 20:21 UTC
    HTML::Table::FromDatabase perhaps?

    my $sth = $dbh->prepare('select * from my_table') or die "Failed to prepare query - " . $dbh->errstr; $sth->execute() or die "Failed to execute query - " . $dbh->errstr; my $table = HTML::Table::FromDatabase->new( -sth => $sth ); $table->print;

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James