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

Re: sorting an associated array

by vinoth.ree (Monsignor)
on Apr 23, 2014 at 20:49 UTC ( [id://1083457]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    %hash = ( Elliot => Babbage,
              Charles => Babbage,
    ...
        ($key, $value) = each %$hashref;
        print "$key => $value\n";
    }
    
  2. or download this
    my %data = (bananas => 1,oranges => 7,apples => 12, mangoes => 3,pears
    + => 8,);
    # Using <=> instead of cmp because of the numbers
    foreach my $fruit (sort {$data{$a} <=> $data{$b}} keys %data) {
        print $fruit . ": " . $data{$fruit} . "\n";
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-18 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found