in reply to sum of integers in a column
You're on the right track, but you're keeping only one total, whereas there are more than one columns. Suddenly I have this nagging feeling that an array to keep the sums would be useful.
A very small hint:
while (my $line = <>) { my @column = split(' ', $line); # $sum[$_] += $column[$i] for 0..$#column; # line corrected by mjscott7202 into: $sum[$_] += $column[$_] for 0..$#column; }
That's two hints, actually. Or three, depending on how you look at it. Anyway, on a side note: you'll also want to use strict; and use warnings;. This will help you catch a lot of errors, typoes, and other mistakes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sum of integers in a column
by mjscott2702 (Pilgrim) on Oct 12, 2010 at 12:36 UTC | |
by muba (Priest) on Oct 12, 2010 at 12:41 UTC | |
by mjscott2702 (Pilgrim) on Oct 12, 2010 at 12:44 UTC | |
by ww (Archbishop) on Oct 12, 2010 at 22:00 UTC |