Re: [Templates] hashes and loops
[prev]
[thread]
[next]
[Date index for 2004/10/21]
On Thu, 21 Oct 2004 11:22:34 -0400, Mark Mills <mark@xxxxxx.xxx> wrote:
> Trond Michelsen wrote:
>=20
> >On Thu, Oct 21, 2004 at 08:47:48AM -0500, Dave Cash wrote:
> >
> >
> >>> while (my $rowref =3D $sth->fetchrow_hashref) {
> >>> foreach (my $href =3D $rowref) {
> >>> my %result =3D %{ $href };
> >>> push @notes, \%result;
> >>> }
> >>> }
> >>>
> >>>
> >>Perhaps I'm not following exactly what you're trying to do, but
> >>could you just do this?
> >>
> >> push @notes, $rowref while my $rowref =3D $sth->fetchrow_hashref;
> >>
> >>
> >
> >According to the DBI documentation, this would be dangerous. Future
> >versions of DBI may reuse the hashref it returns,
> >
> >
> When I want an array of hashes to hand to TT these days, I've gone ahead
> and boiled it down to just this:
> $data =3D $dbh->selectall_arrayref($sql,{Slice=3D>{}})
>=20
> There isn't any reason to iterate over the individual rows when I want
> it all in a struct, and I take the chance that I'll wind up with code
> that kills me if they change the innards. Unless I really need it, I
> don't bother setting up a statement handle any more.
wow. lots of comments!
Selectall iterates over the selected rows specified in the prepare()'s
select statement, correct? If so, then i'm not sure why you would want
to loop through them. My book wasn't clear on this.
$data =3D $dbh->selectall_arrayref($sql,{Slice=3D>{}})
...isn't a push necessary for the DBI spec?
Does this still get around the DBI issue (again below) mentioned in my
book and Trond?
--8<--
Currently, a new hash reference is returned for each row. This
will change in the future to return the same hash ref each time, so
don't rely on the current behaviour.
--8<=AD-
--
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|