package Tie::STHRows; use base Tie::Array; sub TIEARRAY { my $class = shift; my $sth = shift; die "You must pass a statement handler!" unless ref($sth) eq "DBI::s +t"; my %row; $sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } )); bless ([$sth,\%row],$class); } sub FETCH { my $self = shift; $self->[0]->fetch; return +{ %{$self->[1]} }; # per tye's suggestion } sub FETCHSIZE { ${+shift}[0]->rows; }; sub DESTROY { ${+shift}[0]->finish; } 1; __DATA__ sample snippet for how it works: $sth = $dbh->prepare(...); $sth->execute; tie @loopdata, Tie::STHRows, $sth; $template->param(LOOPDATA => \@loopdata); and your template: <TMPL_LOOP NAME=LOOPDATA> ... </TMPL_LOOP>
In reply to Tie::STHRows for HTML::Template loops by antirice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |