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

Okay, I'm baffled. When I go back and look at an AoH that *does* works with an H::T loop, and Dump it, I get something like:

my $allshows = $sth->fetchall_arrayref({}) }; print Dumper($allshows); $VAR1 = [{ 'title' => 'All Bets Are Off', 'type' => '2', 'number' => '215', 'id' => '1' }, { 'title' => 'Who Is My Neighbor', 'type' => '2', 'number' => '217', 'id' => '2' }];

Which matches up with the H::T documentation. When I go back to my original code:

push @$allshows, $sth->fetchall_arrayref({}); ... print Dumper(@$allshows); $VAR1 = [{ 'title' => 'All Bets Are Off', 'type' => '2', 'number' => '215', 'id' => '1' }]; $VAR2 = [{ 'title' => 'Who Is My Neighbor', 'type' => '2', 'number' => '217', 'id' => '2' }];

But when I try dragonchild's I get:

... push @$allshows, @{ $sth->fetchall_arrayref({}) }; ... print Dumper(@$allshows); $VAR1 = { 'title' => 'All Bets Are Off', 'type' => '2', 'number' => '215', 'id' => '1' }; $VAR2 = { 'title' => 'Who Is My Neighbor', 'type' => '2', 'number' => '217', 'id' => '2' };

Seems like I just need to append the single element of the array with hashes. With this I get no error, but no data either:

... $allshows[0] .= $sth->fetchall_arrayref({}); ... print Dumper(\@allshows); $VAR1 = [ 'ARRAY(0x83db738)ARRAY(0x843ef94)' ];

It seems I'm close, but no cigar. What am I missing?


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

Replies are listed 'Best First'.
Re^3: How to get an acceptable H::T AoH ref
by dragonchild (Archbishop) on Sep 11, 2004 at 02:24 UTC
    You're misusing Data::Dumper, which is what's confusing you. D::D takes a list of references to data structures you want to dump out. That's why you're seeing the $VAR1, $VAR2, etc. If you're trying to print out just one thing, you should only see $VAR1. Try the following with my code.
    print Dumper( $allshows );
    You'll get something along the lines of:
    $VAR1 = [{ 'title' => 'All Bets Are Off', 'type' => '2', 'number' => '215', 'id' => '1' }, { 'title' => 'Who Is My Neighbor', 'type' => '2', 'number' => '217', 'id' => '2' } ];
    which is what you want to pass to H::T - an AoH.

    The reason why your last try isn't working is because you're doing string concatenation. The result of assigning an array reference to a string is the ARRAY(0x83db738) crap, which is the type and the memory address of the reference. That isn't what you're looking for, I suspect.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Okay, you are right dragonchild. Thanks for your solution—I would have never figured it out on my own.

      However, nothing worked until I added a slash* in front of @$, so:

      params(showlist => \@$allshows);

      *thanks to the HTML::Template mail serve


      —Brad
      "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton
        Don't do that! You're taking a reference of an array that only exists because you dereferenced a reference to an array. In other words, try param( showlist => $allshows ); before you do that hokey crap from the H::T mail server. Gods! Who came up with that stupidity??

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested