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]";
}