19/03/18 00:38:16.94 9+FFV4Nx.net
>>494 >>496 Perl5
use feature say;
@data = <DATA>;
chomp @data;
@tags = split' ', shift @data;
%idx = map{$_ => $n++} @tags;
@sum = 0 x $n;
for (@data) {
@fs = split' ';
for (0..$n-1) {
$v = $fs[$_];
if ($v =~ /^(\d+\.\d*|\d*\.\d+|\d+)$/) {
$sum[$_] += $v;
} else {
warn "変なデータが紛れ込んでいます_ノ乙(、ン、)_`$v'\n";
}
}
}
for (@tags) {
say "$_ の合計 = ", $sum[$idx{$_}];
}
__DATA__
カラム1 カラム2 カラム3 カラム4
1,0 2.0 3.0 4.0
2.1 3.1 4.1 5.1
~ $ perl 13_494.pl
変なデータが紛れ込んでいます_ノ乙(、ン、)_`1,0'
カラム1 の合計 = 2.1
カラム2 の合計 = 5.1
カラム3 の合計 = 7.1
カラム4 の合計 = 9.1