in reply to declaring arrays dynamically

Howdy!

Do you mean you want a variable number of arrays, @field1, @field2, ... @fieldn where you have n columns, depending on the query?

If so, you could do that, but you really don't want to go that route. Instead, you might consider an array of arrays.

something like:

while (@data = $sth1->fetchrow_array()) { my $col = 0; foreach my $coldata (@data) { push @{$fields[$col]}, $coldata; $col++; } }
should make @fields be an array with one element per column, and each of those elements will be a reference to an array holding the values from each row in row order.

Does that get you where you were trying to go?

yours,
Michael

Replies are listed 'Best First'.
Re^2: declaring arrays dynamically
by jeffa (Bishop) on Sep 15, 2004 at 16:47 UTC

    Well ... you could do that ... ;) or you could do this:

    use DBI; use Data::Dumper; use Math::Matrix; my $dbh = DBI->connect( qw(DBI:vendor:database:host user pass), {RaiseError=>1}, ); my $sth = $dbh->selectall_arrayref('select id,first,last from user'); my $matrix = Math::Matrix->new(@$sth); print Dumper $matrix->transpose;
    Use the CPAN. Write more glue code. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)