I have a data that comes in pair like this:
A: 100
B: 3.3
A: 210
B: 4.3
What I want to do with the code below is to sum value of each pairs:
my $aval = "";
my $bval = "";
while (<DATA>) {
chomp;
if (/^A/) {
$aval = (split(" ",$_))[-1];
}
else {
$bval = (split(" ",$_))[-1];
my $total = $aval + $bval;
print "$total\n";
}
}
However the code above doesn't seem to do what I hope it does.
Especially inside else
the value of $aval
is still empty.
Final result I hope to get is:
103.3
214.3
What's the right way to do it?