Perl sort not working as expected on numeric values

后端 未结 1 1085
北荒
北荒 2021-01-22 03:50

I am stumped by this and obviously missing something basic. It seems perl sort is not working on particular set of value. Here is part of test code:

    use str         


        
相关标签:
1条回答
  • 2021-01-22 04:28

    By default, sort will sort lexically. So 23 and 24 come before 7 for the same reason that bc and bd come before g in the dictionary.

    sort {$a <=> $b} @p will yield a numeric sort.

    http://perldoc.perl.org/functions/sort.html for more info.

    0 讨论(0)
提交回复
热议问题