Thread laufende Summe ueber Hash berechnen
(6 answers)
Opened by Liffi at 2012-06-19 15:29
So kann es gehen:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 my %hash = ( 1=>2, 19=>20, 38=>50, 40=>10, 60=>3, 66=>80, 700=>1 ); my %sums = dosomemagic(\%hash); print Dumper(\%sums); #----------------- sub dosomemagic { my $hash=shift; my %return; my @keys=sort keys(%$hash); while(@keys>=4) { $return{$keys[0]}+=$hash{$keys[$_]} for(0..3); shift(@keys); } return %return; } |