Re: [Templates] hashes and loops

[prev] [thread] [next] [Date index for 2004/10/21]

From: Dave Cash
Subject: Re: [Templates] hashes and loops
Date: 13:47 on 21 Oct 2004
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)

[Templates] hashes and loops
Brandon Hall 19:03 on 19 Oct 2004

Re: [Templates] hashes and loops
Sean Kellogg 19:10 on 19 Oct 2004

Re: [Templates] hashes and loops
Brandon Hall 06:51 on 21 Oct 2004

Re: [Templates] hashes and loops
Michael 13:44 on 21 Oct 2004

Re: [Templates] hashes and loops
Michael 13:58 on 21 Oct 2004

Re: [Templates] hashes and loops
Dave Cash 13:47 on 21 Oct 2004

Re: [Templates] hashes and loops
Sean McAfee 14:34 on 21 Oct 2004

Re: [Templates] hashes and loops
Trond Michelsen 14:44 on 21 Oct 2004

Re: [Templates] hashes and loops
Mark Mills 15:22 on 21 Oct 2004

Re: [Templates] hashes and loops
Darren Chamberlain 19:13 on 19 Oct 2004

Re: [Templates] hashes and loops
Simon Wistow 20:54 on 19 Oct 2004

Re: [Templates] hashes and loops
Brandon Hall 23:56 on 21 Oct 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52