Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
For instance:
Now this is pretty easy to do by just looking at it, there will be exactly 10 rows and 10 columns. Each column will be the same number so the total will be 10, 20, 30, etc.#!/usr/bin/perl -w use strict; $\ = "\n"; foreach my $row ( 1 .. 10 ) { my @output; foreach my $column ( 1 .. 10 ) { push @output , $column; } print join ',' , @output; } # print column totals here
My question is how would you do this if the number of columns was fixed, but the number of rows might vary depending on your data. Furthermore - the code to populate the the @output array is complicated and isn't as easy to determine as the simple foreach loop in my example. I was thinking of an AoA, but I can't get my head wrapped around how to process it afterwards.
Any thoughts?
Thanks in advance - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multi-Column Totals
by bart (Canon) on May 07, 2003 at 22:20 UTC | |
|
Re: Multi-Column Totals
by Abigail-II (Bishop) on May 07, 2003 at 22:28 UTC | |
|
Re: Multi-Column Totals
by shemp (Deacon) on May 07, 2003 at 22:24 UTC | |
|
Re: Multi-Column Totals
by Skeeve (Parson) on May 08, 2003 at 08:12 UTC | |
|
(jeffa) Re: Multi-Column Totals
by jeffa (Bishop) on May 08, 2003 at 15:36 UTC |