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
| [reply] [d/l] [select] |
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
| [reply] [d/l] [select] |
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
| [reply] [d/l] |