Using Perl, how can I sort an array using the value of a number inside each array element?

前端 未结 4 1237
离开以前
离开以前 2020-12-17 04:53

Let\'s say I have an array, @theArr, which holds 1,000 or so elements such as the following:

01  \'12 16 sj.1012804p1012831.93.gz\'
02  \'12 16 sj.1012832p10         


        
4条回答
  •  醉酒成梦
    2020-12-17 05:16

    Here's an example that sorts them ascending, assuming you don't care too much about efficiency:

    use strict;
    
    my @theArr = split(/\n/, < $bVal;
    }
    

    Outputs:

    Before:
    12 16 sj.1012804p1012831.93.gz
    12 16 sj.1012832p1012859.94.gz
    12 16 sj.1012860p1012887.95.gz
    12 16 sj.1012888p1012915.96.gz
    12 16 sj.1012916p1012943.97.gz
    12 16 sj.875352p875407.01.gz
    12 16 sj.875408p875435.02.gz
    12 16 sj.875436p875535.03.gz
    12 16 sj.875536p875575.04.gz
    12 16 sj.875576p875603.05.gz
    After:
    12 16 sj.875352p875407.01.gz
    12 16 sj.875408p875435.02.gz
    12 16 sj.875436p875535.03.gz
    12 16 sj.875536p875575.04.gz
    12 16 sj.875576p875603.05.gz
    12 16 sj.1012804p1012831.93.gz
    12 16 sj.1012832p1012859.94.gz
    12 16 sj.1012860p1012887.95.gz
    12 16 sj.1012888p1012915.96.gz
    12 16 sj.1012916p1012943.97.gz
    

提交回复
热议问题