Tag Archives: DBI

Magic DBI incantation returns array of hashes keyed by column names

my $sql = "select foo, bar, baz from some_table;"; my $result = $dbh->selectall_arrayref($sql, {Slice => {}}); #$result = [ # {foo=>'some data', bar=> 'more data', baz=>'more data'}, # {foo=>'data for row 2', bar=>'....', baz=>'...'}, # {foo=>'data for row 3', bar=>...etc #] It’s the “Slice => {}” part that does it.
Posted in Software Development | Also tagged , | Leave a comment