bsmithsweeney has asked for the wisdom of the Perl Monks concerning the following question:

Hey all,

I have an array of hashes similar to the following structure (but with a lot more records):

@ip_address = (
    {
       IP=> "127.0.0.1",
        COUNT => 2,
    },
     {
        IP => "192.168.0.1",
        COUNT => 5,
    },
);

I'd like to sort this array based on the numerical value of COUNT. I'm sure I need to use the keys function here, but passing that to sort in the proper manner is a bit of a head-scratcher to me. Any suggestions are appreciated! Thanks in advance-

Replies are listed 'Best First'.
Re: sorting an array of hashes
by Ovid (Cardinal) on Sep 10, 2003 at 19:44 UTC
    @ip_addresses = sort { $a->{COUNT} <=> $b->{COUNT} } @ip_address;

    Cheers,
    Ovid

    New address of my CGI Course.

      Thanks!
Re: sorting an array of hashes
by tcf22 (Priest) on Sep 10, 2003 at 19:45 UTC
    my @sorted_ips = sort {$a->{COUNT} <=> $b->{COUNT}} @ip_address;

    - Tom