%HofA = (orange=>['ZZZ', 'ANDY'], red=>['AAA', 'AL'], blue=>['mmm','Betty'], yellow=>['aaa', 'ZEUS'], green=>['DDD','Mary Joe'], violet=>['MMM','Hugo'] );
my @ordered_keys = sort { $HofA{$a}[0] cmp $HofA{$b}[1]
||
$a cmp $b } keys %HofA;foreach $value (@ordered_keys) { print "$value\n"; }
FYI:
Perl Cookbook - 5.4. Traversing a Hash
Problem -- You want to perform an action on each entry (i.e., each key-value pair) in a hash.
Solution -- Use each with a while loop:
while(($key, $value) = each(%HASH)) {
# do something with $key and $value
}Or use keys with a foreach loop, unless the hash is potentially very large:
foreach $key (keys %HASH) {
$value = $HASH{$key};
# do something with $key and $value
}-Sx-
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
