Code:
srand 0; my @letters = split //, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS +TUVWXYZ'; sub rnd_string{ my $string; for( 1 .. (5 + int rand 10)){ $string .= $letters[ rand @letters ]; } #say $string; return $string; } my %hash; for(1 .. 5_000){ $hash{rnd_string()} = rand; } my @sorted_keys; for(1..3_000){ #@sorted_keys = sort { $hash{$b} <=> $hash{$a} } keys %hash; @sorted_keys = reverse sort { $hash{$a} <=> $hash{$b} } keys %hash +; #@sorted_keys = sort { -( $hash{$a} <=> $hash{$b} ) } keys %hash; } say scalar @sorted_keys;
In reply to Re^5: Sorting keys of hash table by values
by lidden
in thread Sorting keys of hash table by values
by iman_saleh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |