Hi
I'm having a problem with
CGI::Application,
HTML::Template and array references. I've got the following code in a sub:
sub get_newsletters {
# ----------------------------------------------------------------
#
my $self = shift;
my $dbh = $self->param('dbh');
use Net::POP3;
my $pop = Net::POP3->new('mail.foo.bar', Timeout => 60);
my $username = "foo";
my $password = "bar";
my (@messages);
if ($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my %row;
my $msg = $pop->get($msgnum);
$row{id} = $msgnum;
$row{email} = @$msg;
warn "print $row{id} - @$msg";
# $pop->delete($msgnum);
push (@messages,\%row);
}
}
$pop->quit;
my $tmpl_path = "view_emails.shtml";
my $tmpl = $self->load_tmpl($tmpl_path, die_on_bad_params => 0);
$tmpl->param (
messages => \@messages,
);
$self->_set_username_in_tmpl(\$tmpl);
return $tmpl->output;
}
And the following in a HTML template file:
<TMPL_LOOP NAME="messages">
<p><TMPL_VAR NAME=id></p>
<p><TMPL_VAR NAME=email></p>
</TMPL_LOOP>
I keep getting the following error message:
[Tue Mar 16 12:11:04 2004] index.pl: Error executing run mode 'get_new
+sletters': HTML::Template->output() : fatal error in loop output : HT
+ML::Template::param() : attempt to set parameter 'email' with an arra
+y ref - parameter is not a TMPL_LOOP! at /usr/local/share/perl/5.8.2/
+HTML/Template.pm line 2905
I'm consfused by this error. I've tried changing @$msg to $msg and the same error appears. I stuck in that warn in the code, and the warn prints the message to stdout perfectly. But for some reason, HTML::Templates chokes.
Any ideas?
- wil
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.