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

Hi! Short question, I'd like to fetch a table (MySQL) and dump it's entire contents to a two dimensional array, so that I could access the data based on column name and row number. I want to do it in the most logic way possible. How do I do it?

Replies are listed 'Best First'.
Re: Representing a table in an array?
by Corion (Patriarch) on Jun 17, 2009 at 12:26 UTC

    DBI, fetchall_arrayref, and the Slice option as Slice => {}:

    use strict; use DBI; use Data::Dumper; my $dbh = DBI->connect(..., { RaiseError => 1, PrintError => 0 }); my $sql = <<SQL; SELECT * FROM mytable SQL my $sth = $dbh->prepare($sql); my $res = $sth->fetchall_arrayref({ Slice => {} }); print Dumper $res;