in reply to sorting hash by value when value is an array ref
You have to have two comparisons, otherwise identical array values will result in keys being displayed out of order. I've included a print line to show how keys and values are accessed after the sort.for (sort {$foo{$a}[1] cmp $foo{$b}[1] or $a cmp $b} keys %foo) { print "$_ -> ['" . $foo{$_}[0] . "', '" . $foo{$_}[1] . "']\n"; }
|
|---|