Monday, January 17, 2011

matrix count in columnwise in perl

undef $/;
$value = <DATA>;
$rcount = @rcount = split(/\n/, $value);

#print $rcount;

for($i = 0; $i <= $rcount; $i++) {
my ($a, $b, $c)=split(/\s+/, $rcount[$i]);
print "$a\t$b\t$c\n";
$x += $a;
$y += $b;
$z += $c;
}

print "$x\t $y \t$z";


__DATA__
1 2 3
4 5 6
7 8 9
2 3 4

No comments: