On Feb 19, 2004, at 10:25 AM, 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.

First, did you catch the later post that pointed out my mistake? Here's the corrected code:


my @ordered_keys = sort { $HofA{$a}[0] cmp $HofA{$b}[0]
                                           ||
                                           $a cmp $b } keys %HofA;


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??

Yes, I only ordered the keys. Sorry if I didn't make that clear. That's all you need though, right? ;)


foreach (@ordered_keys) {
        print "$HofA{$_}[0], $_, $HofA{$_}[1]\n";
}

Hope that helps.

James


-- 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