A "quick and dirty" way to do this task is to use the perl
Command Switches "-F" to do the input, main loop, and splitting. Use an END block to print the summary. Note that the variable @sums must be a declared as a package variable in order to access it in the END block.
(Anyone know a better way?)
#!perl -F','
use strict;
use warnings;
use feature 'state';
state $header = 1;
our @sums;
if ($header) {
printf "%-24s" . " %4s"x10,
'Number', @F[1..10];
$header = 0;
next;
}
chomp $F[10];
for (reverse 2..10) {
$F[$_] = ( ( $F[$_-1] xor $F[$_] ) ? .5 : 0 );
$sums[$_] += $F[$_];
}
$F[1] = 0;
$sums[1] += $F[1];
printf "%-24s " . " %3.1f "x10 . "\n", @F;
END{
our @sums;
printf '*'x75 . "\n";
printf "%-24s" . " %3.1f "x10 . "\n",
"Sum of weights", @sums[1..10];
printf '*'x75 . "\n";
}