in reply to adding array elements

use 5.010; my @s; while (<DATA>) { my @e = split; $s[$_] += $e[$_] for 0 .. $#e; } say "@s";

Replies are listed 'Best First'.
Re^2: adding array elements
by chrestomanci (Priest) on Mar 09, 2011 at 16:11 UTC

    You could also add up the elements on each line with sum from List::Util, so the code above would become:

    use 5.010; use List::Util qw(sum); my @s; push @s, sum( split ) while <DATA> say "@s";
    A reply falls below the community's threshold of quality. You may see it by logging in.