Hi I have a file with following data:
1==0==2 5==3==2 7==1==0
how to add the numerical value column wise. I need to summarize and print it like
1==0==2 5==3==2 7==1==0 13==4==4 * summation column wise (This is what I want to calculate using perl)
I guess you have misunderstood my question. I have edited my question again by ... i meant I have many such column in the table 13==4==4 is the summation column wise which I want add to my file.
I was able to do it for first column only but i need to learn how to for all the other columns as well.my code:
#!/usr/bin/perl
use strict;
use warnings;
open (TEMPTABLE,"temp_data") or die "Cannot open file\n";
my @temp_table_data=< TEMPTABLE > ;
chomp @temp_table_data;
my $total_sum;
for(my $i=0;$i<=$#temp_table_data;$i++)
{
print "$temp_table_data[$i]\n";
my @col=split('==',$temp_table_data[$i]);
for(my $m=0;$m<1;$m++)
{
$total_sum+=$col[$m];
}
}
print "$total_sum\n";
OUTPUT:
1==0==2
5==3==2
7==1==0
13
I don't want to sum ROW but COLUMN.