http://qs321.pair.com?node_id=642006

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

oh great ones,

I have an hash of array. I would like to be able to sort the hash based on the value of the array. But I cannot get to the array in the hash to be able to sort it. the example below does not work becaue I do not know how to pass the array into the sort routine.

code example :

my %colorhash = ( CCgray => ["0","0","0"], CCwhite => ["1","0","0"], CCgrey => ["0","2","0"], CCBlue => ["0","0","3"], ); foreach $colorname (keys %colorhash) { for my $i (0.. $#{ $colorhash{$colorname} } ){ print "[$i] = $colorhash{$colorname}[$i] "; } print "\n"; } my @light2dark = numsort (keys %colorhash); sub numsort { $colorhash{$a}[0] <=> $colorhash{$b}[0] or $colorhash{$a}[1] <=> $colorhash{$b}[1] or $colorhash{$a}[2] <=> $colorhash{$b}[2] }