in reply to Tie::STHRows for HTML::Template loops
and the output was:my $sth = $dbh->prepare('select * from songs limit 5'); $sth->execute; tie my @data, Tie::STHRows, $sth; my $tmpl = q| <tmpl_loop data> <tmpl_var id> <tmpl_var artist> <tmpl_var album> <tmpl_var title> <tmpl_var year> <tmpl_var genre> </tmpl_loop> |; my $template = HTML::Template->new(scalarref => \$tmpl); $template->param(data => \@data); print $template->output;
5 Van Halen Van Halen You Really Got Me 1978 Rock & Roll 5 Van Halen Van Halen You Really Got Me 1978 Rock & Roll 5 Van Halen Van Halen You Really Got Me 1978 Rock & Roll 5 Van Halen Van Halen You Really Got Me 1978 Rock & Roll 5 Van Halen Van Halen You Really Got Me 1978 Rock & RollThe same record. I thought this might happen with my first test ... simply Data::Dumper the contents of @data:
print Dumper \@data; __END__ $VAR1 = [ { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen II', 'title' => 'Spanish Fly', 'year' => '1979', 'id' => '1' }, $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0] ];
print Dumper $_ for @data; __END__ $VAR1 = { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen II', 'title' => 'Spanish Fly', 'year' => '1979', 'id' => '1' }; $VAR1 = { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen II', 'title' => 'Beautiful Girls', 'year' => '1979', 'id' => '2' }; $VAR1 = { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen II', 'title' => 'Dance The Night Away', 'year' => '1979', 'id' => '3' }; $VAR1 = { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen', 'title' => 'Eruption', 'year' => '1978', 'id' => '4' }; $VAR1 = { 'artist' => 'Van Halen', 'genre' => 'Rock & Roll', 'album' => 'Van Halen', 'title' => 'You Really Got Me', 'year' => '1978', 'id' => '5' };
However, this may hinder performance ... but it works for me now:sub FETCH { my $self = shift; $self->[0]->fetch; my %row = %{$self->[1]}; return {%row}; }
1 Van Halen Van Halen II Spanish Fly 1979 Rock & Roll 2 Van Halen Van Halen II Beautiful Girls 1979 Rock & Roll 3 Van Halen Van Halen II Dance The Night Away 1979 Rock & Roll 4 Van Halen Van Halen Eruption 1978 Rock & Roll 5 Van Halen Van Halen You Really Got Me 1978 Rock & Roll
Fun stuff. :) antirice++
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Tie::STHRows for HTML::Template loops
by antirice (Priest) on Jul 30, 2003 at 14:03 UTC |