jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:

I realize there are multitudinous posts of this nature but I have been reading and fell no wiser. I have %info whose values are arrays. I want to do a reverse numeric sort by the value of @{$info{$this_key}}$ndex for instance but my code is giving me a reverse sort of the order in which the keys were initialized as the were read from an excel file???
Any advice is greatly appreciated!
TIA
jg
my @keys = sort { $info{$b} <=> $info{$a} || length($b) <=> length($a) || $a cmp $b } keys %info; foreach (@keys) { print "$_ is @{$info{$_}}[64] <br>" }
_____________________________________________________
Think a race on a horse on a ball with a fish! TG

Replies are listed 'Best First'.
Sorry, Caffeine Deficiency
by jerrygarciuh (Curate) on Mar 19, 2002 at 15:24 UTC
    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
      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