Leser: 33
1 2 3 4 5
my @keys_sorted = sort{ $hash{$a} <=> $hash{$b} }keys %hash; for my $key ( @keys_sorted ) { print "$key -> $hash{$key}\n"; }
1
2
3
4
5
6
7
8
9
10
use strict;
my %hash = ("woche1" => "4",
"woche2" => "3",
"woche3" => "1",
"woche4" => "7",
"woche5" => "2");
my @keys_sorted = sort{ $hash{$b} <=> $hash{$a} }keys %hash;
for my $key ( @keys_sorted ) {
print "$key -> $hash{$key}\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use strict;
my %hash = ();
open (AN, '<', $ARGV[0] ) or die "$!\n";
while (my $line = <AN>) {
chomp $line;
my ($k, $v) = split / /, $line;
$hash{$k} = $v;
my @keys_sorted = sort{ $hash{$b} <=> $hash{$a} }keys %hash;
for my $key ( @keys_sorted ) {
print "$key -> $hash{$key}\n";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
use strict;
my %hash = ();
open (AN, '<', $ARGV[0] ) or die "$!\n";
while (my $line = <AN>) {
chomp $line;
my ($k, $v) = split / /, $line;
$hash{$k} = $v;
}
my @keys_sorted = sort{ $hash{$b} <=> $hash{$a} }keys %hash;
for my $key ( @keys_sorted ) {
print "$key -> $hash{$key}\n";
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; my %hash = (); while (my $line = <DATA>){ chomp $line; my ($k, $v) = split / /, $line; $hash{$k} = $v; } my @keys_sorted = sort{ $hash{$b} <=> $hash{$a} }keys %hash; for my $key ( @keys_sorted ){ print "$key -> $hash{$key}\n"; } __DATA__ woche1 4 woche2 3 woche3 1 woche4 7 woche5 2
local $/="\x0A";
1 2 3 4 5 6
chomp(my @lines = <AN>); my @items = map { [split " ", $_, 2] } @lines; my @sorted = sort { $b->[1] <=> $a->[1] } @items; print "$_->[0] -> $_->[1]\n" for @sorted;
2010-03-26T21:21:27 mikey_bOk. ich dachte das wäre auch möglich ein hash nach werten zu sortieren
Quoteauch wenn es manchmal die schlüsseln gleich sind
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