in reply to Probelm with priority printing (hash or by an array)
You can sort the keys of a hash by value also. You can even sort them by value and by key:
my %h; while (<DATA>) { chomp; my ($v, $k) = split; $h{$k} = $v; } print "$h{$_} $_\n" for sort { $h{$a} <=> $h{$b} || $a cmp $b } keys % +h; __DATA__ 1 Flu 1 Cold 2 Diabetics 4 Impatience 3 Laziness 2 Hubris 3 Typhoid 4 Measle 1 Procrastination
Output:
1 Cold 1 Flu 1 Procrastination 2 Diabetics 2 Hubris 3 Laziness 3 Typhoid 4 Impatience 4 Measle
|
|---|