in reply to DBI efficient loop?

Hello, I am currently using DBI to connect to an MS Access DB and I find it very easy to use the hash_ref rather than an array because you can then pull any field with the name rather than having to use indexes. Some code to demonstrate I’ll assume you already connected to your database:
$dbi_dsn = "dbi:ODBC:<Name of Database>"; ############################# # connect to database $dbh = DBI->connect($dbi_dsn) or die "Can't connect to $dbi_dsn: $DB +I::errstr"; $sth = $dbh->prepare(“Call you query here”); $sth->execute(); while ($hash_ref = $sth->fetchrow_hashref) { $field_1_value = $hash_ref->{Field1}; ... $field_4_value = $hash_ref->{Field4}; }
So now your in a while loop and depending on the name of each field you can access it by calling $hash_ref->{NAME_OF_FIELD} and it loops through the entire table. Hope this helps.