in reply to sorting hash by value when value is an array ref

Here you go,

my @sorted_keys = sort { $foo{$a}[1] <=> $foo{$b}[1] } keys %foo;
(assuming numeric comparison is appropriate) [ Nope, alpha sort is correct, use cmp instead of <=>. I don't know how I missed that part of the question. ]

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: sorting hash by value when value is an array ref
by beachguy82 (Novice) on Nov 16, 2004 at 02:42 UTC
    I must say, I'm amazed by the quick response. This is my first questoin on this board. But back to the question. I had already been trying that bit of code the two of you posted and it doesn't seem to work. My list of keys still isn't sorted by the date. Any clue why? I also tried cmp and <=>.

      Update: Sorry, I see you've already done that.

      The code jdporter and Zaxo provided will indeed do what you ask. There's either an error in your description, or an error in the input you're using. Why don't you provide us a runnable snippet (complete with inputs) so we can continue to help you.

Re^2: sorting hash by value when value is an array ref
by pg (Canon) on Nov 16, 2004 at 02:55 UTC

    cmp is what he is looking for, this will not fully work, as the element is a string not a number. jdporter got it right.

    Update:

    Zaxo already had this fixed before he saw my reply.