Smith Jeff D wrote:
Thanks for the feedback--maybe I screwed up but what happens for me is that
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.
Perl uses its own internal storage method for Hashes.
There is no guarantee of order unless you sort it and
save the results yourself.
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??
You need the key value to get the hash data.
Keys, in of themselves, are of little value.
-----Original Message-----
%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;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>