in reply to How to add MySql Records To Array or Hash?

I'm kind of a beginner, but here is how I would start. I like to use SQL::Abstract and then use empty braces in the fetchall statement to make each element in the array a hash of that row from the SQL table.

#!/usr/bin/env perl use strict; use warnings; use SQL::Abstract; use DBD::mysqlPP; use Data::Dumper; my $dsn = "dbi:mysqlPP:database=$database;host=$hostname"; my $dbh = DBI->connect($dsn,$user,$pass); my $sql = SQL::Abstract->new; my ($stmt,@bind) = $sql->select('quarterbacks'); my $sth = $dbh->prepare($stmt); $sth->execute(@bind); my $results = $sth->fetchall_arrayref({});

Your results ref is an array of hashes. So your first full record might be

$results->[0]; // Reference to a hash ref of Row_1 my %row_1 = %{$results->[0]}; // Hash of Row 1 $results->[0]{name}; // Name column from Row_1 // to iterate over the record set you might do this: // id, position, name are column names from the table for (@{$results}) { my $id = $_->{id}; my $position = $_->{position}; my $qb_name = $_->{name}; }