http://qs321.pair.com?node_id=732315

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

Hello Monks

Is there a easy way to display information that i retrieve from the database using fetchrow_array in a tabular format? i need the users to be able to easily understand what has been retrieved.

The format I am thinking about is:
+--------+---------+--------+
|Heading1|Heading 2|heading3|
+--------+---------+--------+
|
+--------+---------+--------+
Thanks Smanicka

Replies are listed 'Best First'.
Re: is there a way to display tables?
by almut (Canon) on Dec 23, 2008 at 15:59 UTC
Re: is there a way to display tables?
by Bloodnok (Vicar) on Dec 23, 2008 at 17:02 UTC
    You mean over & above format ??

    A user level that continues to overstate my experience :-))
      May I jump in to praise the total awesomeness what Text::Reform is? (if you did not happen to know, Text::Reform is Perl's built-in format on steroids)...
Re: is there a way to display tables?
by tomfahle (Priest) on Dec 24, 2008 at 08:52 UTC

    You should give Text::ASCIITable a try:

    #!/usr/bin/perl use strict; use warnings; use Text::ASCIITable; my $table = Text::ASCIITable->new( {headingText => 'Sales per Year'} ); $table->setCols('Year', 'Sales'); $table->alignCol('Sales' => 'right'); $table->setColWidth('Sales' => 10); $table->addRow(2005, 3000.00); $table->addRow(2006, 4000.00); $table->addRow(2007, 3500.00); $table->addRow(2008, 5800.00); $table->addRowLine; $table->addRow('Average',4075.00); print $table;

    Output

    .-----------------. | Sales per Year | +---------+-------+ | Year | Sales | +---------+-------+ | 2005 | 3000 | | 2006 | 4000 | | 2007 | 3500 | | 2008 | 5800 | +---------+-------+ | Average | 4075 | '---------+-------'

    Hope this helps.
    Thomas

Re: is there a way to display tables?
by Dru (Hermit) on Dec 23, 2008 at 18:19 UTC
    If it's going to be a basic table, (s)printf is another option.

    Thanks,
    Dru

    Perl, the Leatherman of Programming languages. - qazwart
Re: is there a way to display tables?
by jdporter (Paladin) on Dec 23, 2008 at 19:10 UTC
    Any reason you can't format it as HTML and throw it up in a web browser?
Re: is there a way to display tables?
by GertMT (Hermit) on Dec 23, 2008 at 21:15 UTC
    There is

    Data-CTable

    I have version 1.03, that came with a script called tshow.pl and that does what you're looking for. If HTML is allowed I personally like

    Data-Table

    Gert
Re: is there a way to display tables?
by shmem (Chancellor) on Dec 24, 2008 at 02:27 UTC
Re: is there a way to display tables?
by leocharre (Priest) on Dec 29, 2008 at 20:28 UTC
    This is something mysql server etc does automatically via the command line interface. There has to be a stupidly easy way to get that output.
      It must by mysql display rather than API which is used by Perl. It may not be that obvious.
      --Artist