I'm a little stumped on how best to approach a particular problem.  I have a report I'm building that will span an uncertain number of columns and uncertain number of rows.  Below is a sample of what the report might look like:


Account   Descr   Jan   Feb   Jun   Aug   Nov     Total

51112     Fred     $5   $10    $0   $15    $0       $30

51119     Lucy     $0    $0    $7    $0    $0        $7

51121     Ethel    $0   $20    $0    $0    $3       $23

51178     Ricky    $1    $6    $3    $2    $4       $16


The data I pull from the database comes into a result set that looks like this:


Account   Month     Amount

51112        1          5

51112        2         10

51112        7         15

51119        6          7

51121        2         20

51121       11          3

51178        1          1

51178        2          6

51178        6          3

51178        8          2

51178       11          4


So, in effect, only accounts that have amounts in them for any given month will appear in my data set.


The question is:  how do I create my hash references to push into my loop in the correct order so that when I loop through my template, it all appears in the correct column?  I've been able to successfully loop through a structure that has fixed columns and fixed rows, but this one is puzzling me and I don't know where to start.


The best I've come up with so far is to get the last account and its amount to appear in the first two columns, repeated 12 times (definitely not what I want!) by looping through each month that I might have (1-12).


I looked at several examples of nested loops, but I don't seem to be able to figure out what gets nested where.  On the other hand, maybe I need to get my result set to look different??  I don't know SQL that well, but we have folks here who can help me if I need to adjust what the result set looks like.


Thanks for any insights and/or examples you can provide.




P.S.  I was using the model below for nested loops that I found on the web, but I still don't understand what's the @outer_loop_list and what's supposed to be in the @inner_loop_list. 


The Perl stuff:

my @l1;

foreach my $outer ( @outer_loop_list )

                  { my %r1=(outer => $outer);

                    # add more outer-loop stuff here in %r1

                    my @l2;

                    foreach my $inner ( @inner_loop_list)

                                      { my %r2=(inner => $inner);

                                        # add more inner-loop stuff here in %r2

                                        push @l2,\%r2;



                    push @l1,\%r1;


$template->param(outerloop => \@l1);


The .tmpl file:

<tmpl_loop name=outerloop>

  <tr><td><tmpl_var name=outer></td>

      <tmpl_loop name=innerloop>

        <td><tmpl_var name=inner></td>




Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online