Also very convoluted, all of that can be done with:

my $results = $dbh->selectall_arrayref($sql); # if you only want to process a certain amount just LIMIT in your $sql...


I appreciate the response. I tested selectall_arrayref and as I expected, irregardless of the number of rows returned, $results will always point to a matrix. So from what I am seeing, $record->[0] as

Actualyy its an array reference and each element of the array is an array refernce that is the dat areturned by the select.

you have written below would have to be written as $record[0]->[0]. At

nope. $record is one element of the $results array in the for loop,look again:

this point I've come to conclusion that my requirements are causing uneccessary complications. If it wasn't clear, previously I was wanting the data from a sql statement with one row returned to be stored into an array of columns, otherwise make it an array of columns and rows.....

Sounds like you want selectall_arrayref() still... did you read it documentation?


my $results = $dbh->selectall_arrayref("SELECT id, foo, bar FROM baz WHERE $where");

my $count = @{ $results }; # the number of elements in $results (IE the number of rows returned)

for my $record (@{ $results }) { # go through each $record in your $results
    print "Id $record->[0] has a foo of $record->[1]\n";
    print "Id $record->[0] has a bar of $record->[2]\n";
}

I'll simply go with a matrix always and be done with it.

There's no "matrix" :) you're making it too complex on yourself :)

You have an array ref that you can get the number of rows from *and* each record from as an array ref itself, its not nearly as complicated or obscure as a "matrix".

my $count = @{ $results };

$dbh->disconnect;

if($count < 1000) { # or whatever you wanted teh count for...
   for my $record(@{ $results }) {
       # now use the data:
       # $record->[0]
       # $record->[1]
   }
}






Reply via email to