S
SrikanthMandava2004
I have got multiple hashes in an array with same keys. And I want to
count the total of values with same keys.
hash1
score1 20
score2 10
score3 20
hash2
score1 30
score2 20
score3 30
Please note that i have multiple hashes not two as above shown. I am
looking for out put 'Score1 Total = 50; Score2 Total = 30; Score1
Total = 50; ' Looking for the output on the basis of having same key.
I am a perl newbie, have tried the following loop, ended up with some
strange numbers..........advice please
my $sum = 0;
for my $m (0 .. $#notesw){
for $variable (keys %{$notesw[$m]}) {
print "$variable = ${notesw[$m]{$variable}}\n";
$sum += ${notesw[$m]{$variable}};
print "$sum \n";
}
}
count the total of values with same keys.
hash1
score1 20
score2 10
score3 20
hash2
score1 30
score2 20
score3 30
Please note that i have multiple hashes not two as above shown. I am
looking for out put 'Score1 Total = 50; Score2 Total = 30; Score1
Total = 50; ' Looking for the output on the basis of having same key.
I am a perl newbie, have tried the following loop, ended up with some
strange numbers..........advice please
my $sum = 0;
for my $m (0 .. $#notesw){
for $variable (keys %{$notesw[$m]}) {
print "$variable = ${notesw[$m]{$variable}}\n";
$sum += ${notesw[$m]{$variable}};
print "$sum \n";
}
}