Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Probelm with priority printing (hash or by an array)

by shmem (Chancellor)
on Nov 06, 2008 at 14:32 UTC ( [id://722001]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://722001]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found