in reply to Using hashes instead of arrays with database results
I tend to either use hashes or bound values more than arrays anyway.
I use HTML::Template quite a bit and often use the hashref/arrayref calls to match up with a template. For example:
This is from some code that I'm hacking about at the moment, this matches up to a nested <TMPL_LOOP> in the template.my @nodes = (); my $sth = $dbh->prepare(q{ SELECT node_id, title, body FROM node WHERE parent_id = ? }); $sth->execute($parent_id); while (my $row = $sth->fetchrow_hashref) { push @nodes, $row; } $sth->finish; foreach my $node (@nodes) { $sth->execute($node->{node_id}); $node->{children} = $sth->fetchall_arrayref({ node_id => 1, title => 1 }); $sth->finish; } $t->param(NODES => \@nodes);
It's not designed for performance. If it isn't fast enough then there is loads of things I'd do before changing hashes to arrays...
gav^
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) 2Re: Using hashes instead of arrays with database results
by jeffa (Bishop) on Jan 31, 2002 at 15:58 UTC |