Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my %hash = (
- 'L3D0' => '3 0',
- 'L3D7' => '3 7',
- 'L13D0' => '13 0',
- 'L13D1' => '13 1',
- 'L13D7' => '13 7',
- );
- my %hash_1;
- while (my ($k, $v) = each(%hash)) {
- my @a = sort { $a <=> $b } split /[ ]/, $v;
- $hash_1{$k} = \@a;
- }
- sub sort_by_value {
- my ($k_a, $k_b) = @_;
- my @a = @{$hash_1{$k_a}};
- my @b = @{$hash_1{$k_b}};
- return (($a[0] <=> $b[0]) or ($a[1] <=> $b[1]));
- }
- my @sorted_keys = sort { sort_by_value $a, $b } keys %hash_1;
- for my $k (@sorted_keys) {
- print $k, "=>", "@{$hash_1{$k}}", "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement