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.

In reply to Re: DBI efficient loop? by ralife
in thread DBI efficient loop? by lorenzov

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.