in reply to Sorting Hash of Arrays by a Value

my @keys = sort { @{$info{$b}}[$index] <=> @{$info{$a}}[$index] #compare plain +numeric values || length($b) <=> length($a) #if there are matching vals comapre +key length || $a cmp $b #compare chr if ya gotta } keys %info;
Updated 3.19.02 with comments.
_____________________________________________________
Think a race on a horse on a ball with a fish! TG

Replies are listed 'Best First'.
Strange looking comparison block
by RMGir (Prior) on Mar 19, 2002 at 15:57 UTC
    Hmm, your code looks fairly... odd...

    First, I recommend perldoc perldsc.

    It does a good job of covering arrays of hashes, hashes of arrays, and all the other permutations.

    Second, did you mean

    my @keys = sort { $info{$b}->[64] <=> $info{$a}->[64] || length($b) <=> length($a) || $a cmp $b } keys %info;
    I'm not clear on what the structure of info is, from your description. Can you post an example of how it gets initialized?

    Also, your 2nd and 3rd comparisons are a bit strange. Are you really sorting by value, then by the length of the key strings, then finally by the comparison of the keys?

    Odd... The length($b)<=>length($a) step looks quite out of place.
    --
    Mike