I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-06-13 15:18:06.494455-07 by jaiguevara
fetchrow_arrayref AoArefs
I want to load the results of fetchrow_arrayref into an array of arrayrefs. I'm doing something wrong because I end up with a thousand copies of the last row retrieved instead of a thousand unique rows.
######### load the query results into an AoAref's ################### my @qrydata; # I want to load the query rows into this array. my $xx=0; #row counter while (my $row = $sth->fetchrow_arrayref) { # See if the arrayref has the expected data - it does. for my $fld(@$row) { print "$fld|"; } print "\n"; # so push the arrayref onto the AoAref's push @qrydata, $row; # cut it short for test purposes - save 10 rows last if $xx++ >10; } # this prints out 10 copies of the last row fetched!! :( for my $row (@qrydata) { for my $fld(@$row) { print "$fld<"; } print "\n"; }
Any insights would be appreciated. Why am I doing this? I need the total row count before I proceed. I'm thinking this is faster than running SELECT COUNT first for the query, then iterating through the query again. At this point I'm rethinking this, but still want to know what's wrong with my array scheme.
Direct Responses: Write a response