in reply to Re: use of DBI perl function fetchall_arrayref
in thread use of DBI perl function fetchall_arrayref

Ok, Here is what I've got:
my $rows = $sth_tss->fetchall_arrayref; $count = 0; print $CGI->p("rows is ", @$rows); for my $row ( @$rows ) { $CGI->p("Row", ++$count); my @fields = @$row; for my $field ( $fields ) { print $CGI->p($field); } }

and the code it generates is:

ARRAY(0x40285608) ARRAY(0x402856a4) ARRAY(0x40285740) ARRAY(0x402 RRAY(0x40285878) ARRAY(0x402860e0) ARRAY(0x4028617c) ARRAY(0x40286218) + A 02862b4) ARRAY(0x40286350) ARRAY(0x402863ec) ARRAY(0x40286488) ARRAY(0 +x4 ARRAY(0x40287104) ARRAY(0x402871a0) ARRAY(0x4028723c) ARRAY(0x402872d +8) x40287374) ARRAY(0x40287fbc) ARRAY(0x40288058) ARRAY(0x402880f4) ARRAY +(0 0) ARRAY(0x4028822c) ARRAY(0x402882c8) ARRAY(0x40288364) ARRAY(0x40288 +f3 (0x40288fd8) ARRAY(0x40289074) ARRAY(0x40289110) ARRAY(0x402891ac) ARR +AY 248) ARRAY(0x40289e90) ARRAY(0x40289f2c) ARRAY(0x40289fc8) ARRAY(0x402 +8a AY(0x4028a100) ARRAY(0x4028a19c) ARRAY(0x4028ae14) ARRAY(0x4028aeb0) A +RR 8af4c) ARRAY(0x4028afe8) ARRAY(0x4028b084) ARRAY(0x4028b120) ARRAY(0x4 +02 RRAY(0x4028bddc) ARRAY(0x4028be78) ARRAY(0x4028bf14) ARRAY(0x4028bfb0) + A 028c04c) ARRAY(0x4028c0e8) ARRAY(0x4028d100) ARRAY(0x4028d19c)
and so on. What am I doing wrong?

Replies are listed 'Best First'.
Re^3: use of DBI perl function fetchall_arrayref
by davorg (Chancellor) on Jan 26, 2007 at 15:16 UTC
      I made the change, no effect, I'm still getting the same thing. Now, here is my code:
      my $rows = $sth_tss->fetchall_arrayref; # print Dumper $rows; $count = 0; print $CGI->p("rows is ", @{$rows}); for my $row ( @{$rows} ) { $CGI->p("Row", ++$count); my @fields = @{$row}; for my $field ( @fields ) { print $CGI->p($field); } }

      The commented out dumper worked well, I'm definitely getting the data, I just don't know how to access it. I even tried it with just

      my @fields = $row

      and that had no affect. Perl is as bad as C, if it is syntactically correct, it will do something, but not at all what you had in mind.

        Perl is as bad as C, if it is syntactically correct, it will do something, but not at all what you had in mind.

        Beg your pardon?!?

        If you take your keyboard and start typing random words and random punctuation, do you expect the result to make sense? Even if each single word passes the spellcheck? And if you are a tiny bit more carefull and take the time to change it to pass even though the grammar check? Would the random sentences make sense now? And would you pass the history test with that?

        The spelling and grammar check may help, but it's not going to make you a writer so if you expect the syntax check to ensure that your programs do what you wanted you should find a different trade.

Re^3: use of DBI perl function fetchall_arrayref
by Herkum (Parson) on Jan 26, 2007 at 17:55 UTC

    You said that you ran this piece of code., Looking at it you have three print statements that do not appear to be printing out anything similiar to what you posted.

    For example each ARRAY reference should be between p() tags yet it is one long wrapped string.

    Are you sure you looking at the right location for this code?

Re^3: use of DBI perl function fetchall_arrayref
by graff (Chancellor) on Jan 26, 2007 at 22:53 UTC
    This line in your code:
    print $CGI->p("rows is ", @$rows);
    is telling perl to stringify a list of array references and print them out as strings to your web page. And that is exactly what you are seeing. Those "ARRAY(0x....)" things are perl's normal way of converting references into strings.

    Others have pointed other problems with the code, which you might have fixed. Do pay special attention to every "@" and "$", and to the (absence of) spaces around them -- perl is especially picky about those details, because it needs to be.