in reply to How to get an acceptable H::T AoH ref

Use the slice, Luke!

my $things = $dbh->selectall_arrayref(' SELECT id,name FROM status ',{Slice=>{}}); my $t = MyHtmlTemplate->new( handle => \*DATA ); print $t->fill(title=>'FooBar',data=>$things);

Replies are listed 'Best First'.
Re^2: How to get an acceptable H::T AoH ref
by bradcathey (Prior) on Sep 10, 2004 at 20:44 UTC

    Interesting, but I don't think this handles my situation of needing to iterate through several records. If it does, then [motion of hand quickly passing over head from front to back] would you mind unpacking it a bit for me? New stuff.... Thanks.


    —Brad
    "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton
      Ah, I missed that. One way to handle it is to use the IN predicate of SQL instead of doing a loop:
      "WHERE id IN (" . join ',',@ids . ")"
      Another way would be to use the loop but instead of pushing the whole arrayref from the execute into your final array, you need to cycle through each arrayref and push that onto the final array:
      push @$allshows,$_ for @{$sth->fetchall_arrayref({})}; instead of push @$allshows, $sth->fetchall_arrayref({});

        You are quite the SQL guru. And now I have some learning to do. Thanks a lot. I hope all this makes H::T happy in the final analysis.


        —Brad
        "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton