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

Hello, I'm relitively new to Perl, any ideas how I go about displaying customer information in a tabular format in Perl ?. thanks, Richard.

Replies are listed 'Best First'.
Re: Table Help
by marto (Cardinal) on Apr 27, 2006 at 12:40 UTC
    Hi Bern,

    I notice that this is your first post. Welcome to the Monastery.
    Please read the PerlMonks FAQ and How do I post a question effectively? if you have not already done so.
    It would help us if you had provided any existing Perl code you have, and an example of the data.
    The module Text::Table may be of interest to you. Should you need help installing modules check out the Tutorials section of this site.
    If this is not any help to you let me know.

    Hope this helps.

    Martin
Re: Table Help
by blazar (Canon) on Apr 27, 2006 at 12:38 UTC

    Search CPAN. E.g. Text::Table, but other modules may better suit your needs, also because you do not specify where you want to "display customer information": in a web page? on a terminal, as I assumed? in a pdf document?

Re: Table Help
by xorl (Deacon) on Apr 27, 2006 at 14:46 UTC
    Is this a webpage? Just loop thru the data and put the correct html tags in it. Something like this untested typofiled code:
    print "<table border=1>"; while (<DATA>) { my @values = split(/,/, $_); print "<tr><td>" . $value[0] . "</td><td>" . $value[1] . "</td></tr>\n +"; } print "</table>"; __DATA__ foo,bar baz,quux Mike,Micky Davy,Peter
    Output should be something like:
    foobar
    bazquux
    MikeMicky
    DavyPeter
    If you're not creating a webpage please use the suggestions already provided.
      Ew, good God, if you're going to do that, use CGI.
      use strict; use warnings; use CGI; my $q = CGI->new; my @values = grep {@$_} map {chomp; [split ',']} <DATA>; my $rows = "\n"; $rows .= $q->Tr ( {align => 'center', valign => 'top'}, [$q->td ([$_->[0]]) . $q->td ([$_->[1]])] ) . "\n" for @values; print $q->header, $q->start_html, $q->table({border => 1}, [$rows]); __DATA__ foo,bar baz,quux Mike,Micky Davy,Peter
      meh.
Re: Table Help
by moklevat (Priest) on Apr 27, 2006 at 16:13 UTC
    It's not clear exactly what you want to do, but you have some good answers above.

    If you are doing text (terminal) tables, I would add my recommendation for Perl6::Form.

Re: Table Help
by TedPride (Priest) on Apr 27, 2006 at 19:28 UTC
    use strict; use warnings; my ($i, @arr, $separator, @lengths, $length, $format); @arr = ( ['', qw/COL1 COL2 COL3 COL4/], [qw/COL1 once upon a time/], [qw/COL2 there was a little/], [qw/COL3 table of data/] ); $separator = ' | '; for (@arr) { for $i (0..$#$_) { $lengths[$i] = length($_->[$i]) if !$lengths[$i] || $lengths[$ +i] < length($_->[$i]); } } $length = 0; $length += $_ for @lengths; $length += length($separator) * $#lengths + 4; $format = join $separator, map { '%-'.$_.'s' } @lengths; print '-' x $length, "\n"; print '| ', sprintf($format, @$_), ' |', "\n", '-' x $length, "\n" for @arr;
    Returns:
    --------------------------------------- | | COL1 | COL2 | COL3 | COL4 | --------------------------------------- | COL1 | once | upon | a | time | --------------------------------------- | COL2 | there | was | a | little | --------------------------------------- | COL3 | table | of | data | | ---------------------------------------
    Should be fairly easy to punch in your data.