Re: [Templates] hashes and loops
[prev]
[thread]
[next]
[Date index for 2004/10/21]
On Wed, 20 Oct 2004, Brandon Hall wrote:
> On Tue, 19 Oct 2004 12:10:20 -0700, Sean Kellogg
> <skellogg@x.xxxxxxxxxx.xxx> wrote:
> > Whenever I have passed an array like yours, I have found it best to push an
> > anonymous hash like this
> >
> > push @emails, { from => "fred", to => "wilma", subj => $subj , date =>
> > "today"};
> >
> > and then pass the array to the template with a slash.
> >
> > my $vars = {
> > message => "Hello World\n",
> > emaillist => \@emails
> > };
>
> That solved it magnificently! Now i'm trying to clean it up so I don't
> have to specify the fields and I can cut and paste more code ...so. I
> wrote this using what I've learned. This snip works, but I don't think
> it's correct. I think there is a perl fudge making it work ;)
>
> while (my $rowref = $sth->fetchrow_hashref) {
> foreach (my $href = $rowref) {
> my %result = %{ $href };
> push @notes, \%result;
> }
> }
>
> This way, in the template I can just use the database fields. eg,
> timestamp, id, param1, etc.
Perhaps I'm not following exactly what you're trying to do, but
could you just do this?
push @notes, $rowref while my $rowref = $sth->fetchrow_hashref;
or if that doesn't work:
while ( my $rowref = $sth->fetchrow_hashref ) {
push @notes, $rowref;
}
I hope that helps.
Dave
/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash Power to the People!
Frolicking in Fields of Garlic Right On-Line!
dave@xxxxx.xxx Dig it all.
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|