in reply to Getting Record Set via DBI into an Array of Arrays

while (my $row = $sth->fetch()){ push @{ $data[0] }, $row->[0]; push @{ $data[1] }, $row->[1]; }

Note that passing scalars to Data::Dumper produces better results.

print Dumper(\@data);

Update: Fixed missing arrows too.

Replies are listed 'Best First'.
Re^2: Getting Record Set via DBI into an Array of Arrays
by overrider (Acolyte) on Apr 13, 2009 at 07:30 UTC
    Hi there, using
    while (my $row = $sth->fetch()){ push @{ $data[0] }, $row[0]; push @{ $data[1] }, $row[1]; } print Dumper(@data);
    produced this:
    $VAR1 = [ undef, undef, undef, undef, undef ]; $VAR2 = [ undef, undef, undef, undef, undef ];
    Using
    while (my @row = $sth->fetchrow_array()){ push @{$data[0]}, $row[0]; push @{$data[1]}, $row[1]; } print Dumper(@data);
    produced this:
    $VAR1 = [ 'Siemens', 'Ericcson', 'Nokia', 'Sony', 'Samsung' ]; $VAR2 = [ '45000', '18000', '12000', '11000', '8000' ];
    so the last one there is exactly what i needed! Thanks a lot.
      Sorry, was tired. I meant
      while (my $row = $sth->fetch()){ push @{ $data[0] }, $row->[0]; push @{ $data[1] }, $row->[1]; }
      My code would have given you a compile-time error had you used use strict;.