in reply to how to sort hash of array by value

You forgot to sort it!
use Data::Dumper; my %colorhash = ( CCgray => [ "0","0","0" ], CCwhite => [ "1","0","0" ], CCgrey => [ "0","2","0" ], CCBlue => [ "0","0","3", ] ); my @light2dark = sort numsort (keys %colorhash); print Dumper \@light2dark; sub numsort { $colorhash{$a}[0] <=> $colorhash{$b}[0] or $colorhash{$a}[1] <=> $colorhash{$b}[1] or $colorhash{$a}[2] <=> $colorhash{$b}[2]; }

Output:

$VAR1 = [ 'CCgray', 'CCBlue', 'CCgrey', 'CCwhite' ];

Replies are listed 'Best First'.
Re^2: how to sort hash of array by value
by blkperl (Initiate) on Oct 01, 2007 at 22:51 UTC
    oops, but it still does not change the order based on the value. There is not change in the hash order.
      The hash order is always random, and has nothing to do with the order in which that hash was created.

      Compare the following snippet with the original:

      use Data::Dumper; my %colorhash = ( CCgray => [ "0","0","0" ], CCwhite => [ "1","0","0" ], CCgrey => [ "0","2","0" ], CCBlue => [ "0","0","3", ] ); my @light2dark = keys %colorhash; print Dumper \@light2dark;

      PS Have you enclosed your original program within <code>...</code> tags yet?