Octavian Rasnita wrote:
I have a hash that have multiple sub hashes and I want to sort it
by a sub key.

For example, I have:

$comp{$code}{$year}{profit}.

And I want to sort the $code values after the value of the "profit"
key.

Is this possible directly, or I will need to create another hash
for doing this type of sort?

You don't need another hash.

    perldoc -f sort
    perldoc -q "sort a hash"

    my @codes = sort {
        $comp{$a}{$year}{profit}
                  <=>
        $comp{$b}{$year}{profit}
    } keys %comp;

Your question has absolutely nothing to do with CGI, so you should
have posted it to the [EMAIL PROTECTED] list instead.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to