develooper Front page | perl.beginners | Postings from February 2002

RE: sort on anonymous array elements as hash values

Thread Previous | Thread Next
From:
Nikola Janceski
Date:
February 6, 2002 08:48
Subject:
RE: sort on anonymous array elements as hash values
Message ID:
1449413DA482D311B67000508B5A12F50592DCBF@nyexchange01.summithq.com
yes:

@sorted_keys = sort { $hash{$a}[2] cmp $hash{$b}[2] } keys %hash;

-----Original Message-----
From: birgit kellner [mailto:birgit.kellner@aon.at]
Sent: Wednesday, February 06, 2002 11:36 AM
To: beginners@perl.org
Subject: sort on anonymous array elements as hash values


my %hash = (
	'keyone' => ['firstvalueone', 'firstvaluetwo],
	'secondkey' => ['anothervalueone', 'valuetwoforsecondkey'],
	'keythree' => ['thirdvalueone', 'thirdvaluetwo']
	
);

Can I sort the hash on the second element of the anonymous array?

Output should be:

firstvaluetwo
thirdvaluetwo
valuetwoforsecondkey


Many thanks in advance,


Birgit Kellner

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About