The reason why the first code works is because the TMPL_LOOP selscene is expecting an array of hashes. When you work with it, $data->[1] is a hashref. So, what you want to do is:
Example A, rewritten: my $data = $sth->fetchall_arrayref({}); if ($data->[0]{title} eq 'large') { ucase( $data->[0]{title} ); } print "First title: '$data->[0]{title}'\n"; $template->param( selscene => $data );
A few comments, in no particular order:
It's a lot easier to read and you still have all the error handling. You may want to turn PrintError off, if you do this.eval { my $sth = $dbh->prepare_cached( ... ); $sth->execute; my $stuff = $sth->festchall_arrayref({}); $template->param( selscene => $data ); }; if ($@) { # Do some error handling here. }
------
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
In reply to Re: Dereferencing fetchall_arrayref({})
by dragonchild
in thread Dereferencing fetchall_arrayref({})
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |