Thread Hash sortieren
(19 answers)
Opened by mikey_b at 2010-03-26 22:08
Hier das Beispiel von "wer" angepasst auf deine Anforderung
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #!/usr/bin/perl use strict; use warnings; my %hash = (); while (my $line = <DATA>){ chomp $line; my ($k, $v) = split / /, $line; # geƤnderte zeile $hash{$k} = $v if(!exists($hash{$k}) or $hash{$k} < $v); } my @keys_sorted = sort{ $hash{$b} <=> $hash{$a} }keys %hash; for my $key ( @keys_sorted ){ print "$key -> $hash{$key}\n"; } __DATA__ woche 4 woche 3 week 2 semana 1 woche 7 week 4 semana 9 vecka 3 |