Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Hash value sorting

by greengaroo (Hermit)
on Aug 14, 2012 at 12:57 UTC ( #987344=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Hash value sorting
in thread Hash value sorting

Try this:

foreach my $key ( sort { $self->{_counts}->{$a} <=> $self->{_counts}->{$b} } keys %{ $self->{_counts} }

If you do $self->{_counts}{$b}, Perl thinks $self->{_counts} is a real Hash, not an HashRef. If you use the arrow to dereference, it is easier to read.

Take my advice. I don't use it anyway.


Comment on Re^3: Hash value sorting
Download Code
Replies are listed 'Best First'.
Re^4: Hash value sorting
by daxim (Chaplain) on Aug 14, 2012 at 13:34 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2015-07-30 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls