in reply to HTML::Template problems

I think your main problem is in this snippet:

my (@data) = q[$thread->{id}, $thread->{name}, $thread->{date}, $thread->{subj}, $thread->{day_rate}, $thread->{msg}];

You're creating an array with only one element. Your snippet is equivalent to the following. Note that q() is equivalent to the single-quote operator, so the values won't even be interpolated into the string.

my @data = '$thread->{id}, $thread->{name}, ' . '$thread->{date}, $thread->{subj}, ' . '$thread->{day_rate}, $thread->{msg}';

Perhaps you meant something like:

my @data = ( $thread->{id}, $thread->{name}, $thread->{date}, $thread->{subj}, $thread->{day_rate}, $thread->{msg} );

Update: Fixed the 'equivalent' example to single quotes and added explanation (originally was concatenating with double quotes which would not be the same).

Replies are listed 'Best First'.
Re: Re: HTML::Template problems
by stonecolddevin (Parson) on Dec 31, 2003 at 23:31 UTC
    Ahhhh, of course. I'll try it and get back to this.
    Thanks,
    -dhoss

    "and I wonder, when I sing along with you if everything could ever feel this real forever? if anything could ever be this good again? the only thing I'll ever ask of you, you've gotta promise not to stop when I say 'when'", she sang
      Ahh, now instead of 14, it's returning 84.....?

      "and I wonder, when I sing along with you if everything could ever feel this real forever? if anything could ever be this good again? the only thing I'll ever ask of you, you've gotta promise not to stop when I say 'when'", she sang
        Why don't you use Data::Dumper to see exactly what @msgs looks like before you return it?
        warn Dumper \@msgs;
        Now, unless your code looks something like this:
        while ( my $thread = $sth->fetchrow_hashref() ){ my (@data) = $thread->{id}, $thread->{name}, $thread->{date}, $thread->{subj}, $thread->{day_rate}, $thread->{msg}; push @msgs, \@data; } return @msgs; # although i would likely return \@msgs ...
        You will likely run into trouble. But why are you even doing this? Such a waste of effort and time when a simpler solution is just around the corner:
        sub selectMsgFromDb { my ($self, %params) = @_; $self->checkRequiredParams(%params); my $sth = $dbh->prepare( $cfg->{retrieve_from_sql}->{msg} ); $sth->execute; my $messages = $sth->fetchall_hashref({}); # warn Dumper $messages; # in case you don't believe me ;) return $messages; }
        Yes, that's really all you need to do, because fetchall_hashref (when passed a single hash reference) will return a LoH ... which is exactly what an HTML::Template <tmpl_loop> needs.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)