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

hi, while using Data::Table I can create a table like this:
# !/usr/bin/perl -w use strict; use diagnostics; use Data::Table; my $table = new Data::Table( [ [ 20070410, 20070415, 20070417, 20070418 ], [ 10, 20, 15, 42 ] ] +, [ 'Dates', 'Values' ], 1 ); print $table->csv;
Can someone explain me what I'm doing wrong if I try
# !/usr/bin/perl -w use strict; use diagnostics; use Data::Table; my $dates = "20070410, 20070415, 20070417, 20070418"; my $quan = "10, 20, 15, 42"; my $table = new Data::Table( [ [$dates], [$quan] ], [ 'Dates', 'Values +' ], 1 ); print $table->csv;
Thanks,
Gert

Replies are listed 'Best First'.
Re: Data::Table and defining $data
by shigetsu (Hermit) on May 11, 2007 at 12:08 UTC

    You're passing strings ($dates, $quan) instead of arrays (@dates, @quan) to the constructor:

    Replace

    my $dates = "20070410, 20070415, 20070417, 20070418"; my $quan = "10, 20, 15, 42"; my $table = new Data::Table( [ [$dates], [$quan] ], [ 'Dates', 'Values +' ], 1 );

    with

    my @dates = (20070410, 20070415, 20070417, 20070418); my @quan = (10, 20, 15, 42); my $table = new Data::Table( [ [@dates], [@quan] ], [ 'Dates', 'Values +' ], 1 );
    and it should work (tested).

      geeh, what can I say. Very good I can finally continue!
      Thanks,
      Gert