the ordered array (1) only lists the keys, not the array values the hash key
points to and (2) I still don't get an ordered list of the keys that are put
in the "ordered" array--it comes out un-ordered.
I took your line and just added a for loop/print for the ordered array and
got "red,yellow,blue, orange, violet, green" only as the result.
I must be dense but using just a Keys expression can't return the values,
can it??--wouldn't it be better to do a while/each and get both key and
value for the HofA somehow??
-----Original Message-----
From: James Edward Gray II
Sent: Wednesday, February 18, 2004 6:49 PM
To: Smith Jeff D
Cc: [email protected]
Subject: Re: An Old Question on Sorting Hash of Arrays by Array element and
th en by key
On Feb 18, 2004, at 1:58 PM, Smith Jeff D wrote:
I am trying to sort a hash of arrays that is similar to the example
below.
I have a hash of arrays that I want to sort, first by the first
element of
the array, then by the key to the hash and don't care about other
elements
of the array (for sorting and without regard to case.
%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]I am trying to sort a hash of arrays that is similar to the example
below.
I have a hash of arrays that I want to sort, first by the first
element of
the array, then by the key to the hash and don't care about other
elements
of the array (for sorting and without regard to case.
%HofA = (orange=>['ZZZ', 'ANDY'],
red=>['AAA', 'AL'],
blue=>['mmm','Betty'],
yellow=>['aaa', 'ZEUS'],
green=>['DDD','Mary Joe']
violet=>['MMM','Hugo']
);
$a cmp $b } keys %HofA;
I believe that will do it. See if that gets you going.
James