in reply to By ref or by ..well..ref!

Well, first off...welcome and congratulations on your first post. ('Bout time, dang it.)1

Second, be sure to take some time to browse through some of the site docs on the markup you can use to provide nicely formatted messages, especially this bits about <CODE> tags. Try looking at some the documents linked here.2

Third--and finally--I think the problem lies in your second line:

$loop_data=[ {Auction=>'Test1', ID=>'1'}, {Auction=>'Test2', ID=>'2'}, {Auction=>'Test3', ID=>'3'}, {Auction=>'Test4', ID=>'4'}, ];

I think you want @loop_data=... instead. ;-)

I hate this computer, I wish they would sell it.
   It doesn't do what I want...only what I tell it.

-- Reader's Digest, circa 1983

--f

1 - growlf is the one that pointed me to this site over a year ago. I've been after him to post since then. While you might want to blame him for unleashing me on y'all, you can forgive me for giving him a bit of a bad time. (I can now say I've met two monks in RL.)

2 - Alternatively, you could /msg me or answer when I try to talk.

Replies are listed 'Best First'.
The fetchall_answer!
by growlf (Pilgrim) on Oct 20, 2001 at 11:39 UTC
    Thanks again, all! I have found the way to make fetchall_arrayref() act as expected - good ol' O'Reilly saves the day. To make fetchall_arrayref() pass a reference to an array of references to hashes (instead of a reference to an array of hashes - very subtle diference, but error prone in this need): merely pass the method a template hash to use internally as an example. i.e.:

    my $arrayref = $sth->fetchall_arrayref({ FieldID =>1, Fieldname2 =>1, Fieldname3 =>1, Fieldname4 =>1, }); $template->param(table1 => $arrayref);


    Update:Or even more simply:
    my $arrayref = $sth->fetchall_arrayref({}); $template->param(table1 => $arrayref);


    This worked exactly as expected and dropped both code size and execution time dramaticly. Not to mention leaving me with HTML::Template's standard HTML file style that my clients can mess with easily without having to learn anything new. No sense re-writing the wheel, when it does what it is supposed to - once i learned HOW it does it. Took a bit of reading the source of the DBI and HTML libs though. Guess I need to really brush up on passing of references for stuff like this.
      This is the kind of problem which Data::Dumper is very helpful for. If you run it on the database output you will find that you are getting back array references rather than hash references.

      This is the thing I most dislike about DBI's API. There are a ton of efficient ways to use positional logic, but if you want to use name-based logic, you are definitely a second-class citizen. However name-based logic is much better from a development perspective if performance is not utterly critical.

      But anyways you can just use a bit of code like this:

      # Takes a statement handle, and returns the entire result # set as a reference to an array of hashes. sub fetchall_arrayref_hash { my $sth = shift; my @rows; while (defined(my $row = $sth->fetchrow_hashref())) { push @rows, $row; } return \@rows; } # Then elsewhere $template->param(table1 => fetchall_arrayref_hash($sth));
      The fact that someone doesn't provide the interface that you want is no reason not to provide it yourself...
      Hello,

      fetchall_arrayref() returns a reference to an array of array.
      $ref = $sth->fetchall_arrayref(); $ref = [ ['test1', 1], ['test2', 2] ];
      It does not return a reference to an array of hashes.
      $ref = [ {data => 'test1', ID => 1}, {data => 'test2', ID => 2} ];
      And because of that difference you can not pass it directly to the template-module. But you could change your template-module to accecpt arrays instead of hashes.

      Good bye,
      uwe