Hello:

I have what seemed like a simple problem at first, but I cannot get my code to work. Basically, I have a simple SQL SELECT statement (which returns only 3 fields) I am performing on a MySQL database using DBI and DBD::mysql. I want to do a fetchrow_array, then take each returned row and push it into a multidimensional array. What it looks like the code below gets me is an array of arrays with the correct number of elements from the SELECT statement, but the @drivers array I am pushing into contains the arrays with no data. To make sure I am getting the data out of the database properly, I can print the @arr and return the expected data. Am I missing something obvious here, or am I just going about this all wrong? Is there a better way to return db results into an array of arrays?

Thanks, and btw, this is by far the most helpful perl resource on the web.
# build multidimensional array from results while (@arr = $sel->fetchrow_array) { push (@drivers, \@arr); # prints the correct data from the db print "arr: @arr\n"; } # prints the right number of ref's print @drivers; # this just prints the commas and the spaces foreach my $item (@drivers) { print "$item->[0], $item->[1], $item->[2]"; }

In reply to Array of Arrays from DB by Anonymous Monk

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.