in reply to Re^3: How can you make this script general?
in thread How can you make this script general?
to be prepared for the general case, where the columns have names...
Still makes no sense to waste cycles sorting hash keys:
#! perl -slw use strict; my @colnames = split ' ', <DATA>; my @totals; while( <DATA> ) { my @cols = split; $totals[ $_ ] += $cols[ $_ ] for 0 .. $#cols; } printf "%10s:%u\n", $colnames[$_], $totals[$_] for 0 .. $#totals; __DATA__ alpha beta gamma delta 1 2 3 4 5 6 7 8 9 10 11 12
Produces:
C:\test>junk alpha:15 beta:18 gamma:21 delta:24
|
|---|