Perl: Numerical sort of arrays in a hash 2 (Schwarzian Transform)

五迷三道 提交于 2019-12-02 10:41:42

You are doing a cmp on the first column. That means it sorts it as text. Your sort function should be:

sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } ...

Which makes the output:

13.52 0.09 bumbo
9.999 0.001 dog
3.52 0.34 lala
0.899 0.92 cat
-0.52 0.3 humpty
-1.52 0.98 nanny

However, you should never need to put a reverse before sort, because you can always reverse the terms:

sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!