Re: [htmltmpl] hashref and HTML::Template question
Brought to you by:
samtregar
From: Sam T. <sa...@tr...> - 2002-09-28 17:32:58
|
On Sat, 28 Sep 2002, Irubin Consulting wrote: > I know the problem is that I am pushing two seperate rows into the > short_consolidate array reference. This causes two loops to run instead of > the desired one. That could be the problem. Your example isn't complete enough to run, and you don't say exactly what isn't working, so I can only really guess. But if that is the problem then you should change this code: push @{$short_consolidate}, $_; push @{$creditor}, $_ while $_ = $sth1->fetchrow_hashref(); push @{$short_consolidate}, {Creditor => \@{$creditor}}; To: my $row = $_; push @{$creditor}, $_ while $_ = $sth1->fetchrow_hashref(); $row->{Creditor} = \@{$creditor}}; push @{$short_consolidate}, $row; That should fix the problem you mentioned. However, while I've got your attention I think there are a couple other problems in this code. First, you're abusing $_ and it's not making anything easier for yourself. Instead of: while ($_ = $sth->fetchrow_hashref()) { Why not use: while (my $row = $sth->fetchrow_hashref()) { Then you have a nice named lexical variable ($row) instead of a nasty global that you have to worry about overwriting later. Second, speaking of lexical (my) variables, are you using them? Your code looks like it could be using only global variables. This will definitely cause you problems in the future (if it isn't already!). I strongly suggest you pick up a good (O'Reilly) Perl book and drink the lexical variable koolaid. Good luck, -sam |