use 5.010; # for // operator use warnings; use strict; use Data::Dump; use Test::More # tests => ?? + 1 # Test::NoWarnings adds 1 test 'no_plan' ; use Test::NoWarnings; my @totals; while (my $line = ) { chomp $line; my @fields = split ' ', $line; for my $i (0 .. $#fields) { # $totals[$i] = $fields[$i] + (defined($totals[$i]) ? $totals[$i] : 0); $totals[$i] = $fields[$i] + ($totals[$i] // 0); } # dd \@fields; dd\@totals; # FOR DEBUG } my $max_input_cols = @totals; ok $max_input_cols == 5, qq{max number input columns}; is_deeply \@totals, [ 21, 176, 909, 6006, 20002 ], qq{column totals}; printf qq{max cols in input data: %d \n}, $max_input_cols; print qq{column totals: \n}; printf qq{%6d}, $_ for 0 .. $#totals; print qq{\n}; for my $col (@totals) { printf qq{%6d}, $col; } print qq{\n}; __DATA__ 1 11 2 22 202 2002 20002 3 33 303 4 44 404 4004 5 6 66