排序和比较 [英] sort and compare

查看:76
本文介绍了排序和比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试根据数值对列进行排序,但在我看来,perl根据列的第一个值进行排序。例如,我文件中的一些数据是23,5467,21,64,654,342,10 *
当我在这些数字的数组上使用sort函数时,它基于第一个排序数字而不是基于总价值。喜欢它分类10,21,23,342,5467,64,654,但我试图得到基于5467,654,342,64,23,21,10的价值。


任何帮助将是赞赏。

谢谢

Kumar

Hi All,
I am trying to sort a column based on the numerical value but it seems to me that perl sorts based on first value of the column. For example, some of the data in my file is 23, 5467, 21, 64, 654, 342, 10
When i used the sort function on the array of these numbers, it sorted based on first numerical number and not based on total value. Like it sorted 10, 21, 23,342,5467, 64,654 but i am trying to get based on value like 5467,654,342,64,23,21,10.

Any help will be appreciated.
Thanks
Kumar

推荐答案

所以,你想要用两种方式排序,首先,但是数字的长度,然后进行子排序,将它们按每个长度的顺序排列,从最大到最小(反向排序)。


到目前为止您尝试过哪些代码?在我们帮助您之前,您需要向我们展示您所做的事情。


BTW,请将您的代码放入代码标签中。一个例子显示在答复指南中。回复窗口右侧的框。


问候,


Jeff
So, you wanted sorted in two ways, first, but the length of the number, and then a sub-sort to put them in order of each length, largest to smallest (reverse sort).

What code have you tried thus far? You need to show us what you have done before we can help you.

BTW, please put your code in code tags. An example is shown in the "Reply Guidelines" box to the right of the reply window.

Regards,

Jeff


要用数字排序你必须使用数值比较运算符< ; =>:

to sort numerically you have to use the numeric comparison operator <=>:

展开 | 选择 | Wrap | 行号


感谢您的回复,

here是我的代码
Thanks for your reply,
here is my code
展开 | 选择 | Wrap | 行号


这篇关于排序和比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆