in reply to perl DBI question about fetchrow_arrayref()

Your question says "fetchrow_arrayref", but in your example you are using fetchrow_array.

Maybe that's why it doesn't work ??

Update: As per the sabari Answer which is correct, here's what you need

my $list = $db->prepare("SELECT * FROM `table`"); $list->execute(); my @array; while ( my $ref = $list->fetchrow_arrayref() ) { push @array,[@$ref]; } foreach (@array) { print @{ $_ },"\n"; }
OR
my @array; while ( my @arr = $list->fetchrow_array() ) { push @array,\@arr; } foreach (@array) { print @{ $_ },"\n"; }

Replies are listed 'Best First'.
Re^2: perl DBI question about fetchrow_arrayref()
by sabari (Beadle) on Apr 25, 2010 at 08:06 UTC
    The issue is simple ,during the push your inserting the ref not the value .So the last value printed many time while printing ,since the array contains the only list of ref . Like what your doing during in the first print here also you needs to insert the value not ref .
    Best Regards, S.Sabarinathan,

      Thank you Sabarinathan. This thing really confuses me.

      now I understand, that when I used push, the ref finally pointed to the last record, so when I deferenced it, all the values became the last record.

Re^2: perl DBI question about fetchrow_arrayref()
by lightoverhead (Pilgrim) on Apr 25, 2010 at 09:48 UTC

    Thank you ahamad for giving me a detailed solution.

    This should work

Re^2: perl DBI question about fetchrow_arrayref()
by Anonymous Monk on Apr 25, 2010 at 13:54 UTC
    Your question says "fetchrow_arrayref", but in your example you are using fetchrow_array.
    Did someone update the post without noting it? The post does say fetchrow_arrayref. :-(
      yes