packetstormer has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone recommend how to pass and array of array references to Template::Toolkit to be dereferenced and displayed? Function called:
Perl script (extract of):sub return_values { my $dbh = FuncClass::Connect->dbh; my $query = "SELECT name,address,phone,email,account#,date from mytable where id_code = ?"; my $sth = $dbh->prepare($query); $sth->execute($_); my @return_rows; while (my @row = $sth->fetchrow_array()) { push @return_rows, \@row; } $sth->finish(); $dbh->disconnect(); return \@return_rows;
Template file:#!/usr/bin/perl use strict; use warnings; use CGI; my $query = new CGI; my ( $template, $user, $cookie ) = build_office_template ( { template_name => 'office/display.tt', query => $query, type => "office", } ); my $results = &return_values; my $sendoff = @$results; $template->param('results' => \@sendoff); output_html_with_http_headers $query, $cookie,
Now, if the \@sendoff is just an array reference this will display correctly. However, because its an array of array references its not displaying anything.[% FOREACH line IN results %] [% line %] [% END %]
Should I deference it, bind the columns and then sent it to Template? Any suggestions would be great
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing array of references to Template
by philipbailey (Curate) on Aug 23, 2011 at 19:54 UTC | |
by packetstormer (Monk) on Aug 23, 2011 at 20:01 UTC | |
by philipbailey (Curate) on Aug 23, 2011 at 20:06 UTC | |
by packetstormer (Monk) on Aug 23, 2011 at 20:27 UTC | |
|
Re: Passing array of references to Template
by locked_user sundialsvc4 (Abbot) on Aug 24, 2011 at 12:32 UTC |