How to do alpha numeric sort perl?

前端 未结 3 376
迷失自我
迷失自我 2021-01-28 02:46

I have a file which looks like this:

80,1p21  
81,19q13  
82,6p12.3  
83,Xp11.22  
84,3pter-q21  
86,3q26.33  
87,14q24.1-q24.2|14q24|14q22-q24  
88,1q42-q43  
8         


        
3条回答
  •  鱼传尺愫
    2021-01-28 03:30

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    my @datas   = map { /^(\d+),(\d*)(.*)$/; [$1, $2, $3]; } ;
    my @res     = sort {$a->[1] <=> $b->[1] or $a->[2] cmp $b->[2]} @datas;
    foreach my $data (@res) {
        my ($x, $y, $z) = @{$data};
        print "$x,$y$z\n";
    }
    
    __DATA__
    80,1p21
    81,19q13
    82,6p12.3
    83,Xp11.22
    84,3pter-q21
    86,3q26.33
    87,14q24.1-q24.2|14q24|14q22-q24
    88,1q42-q43
    89,11q13.1
    90,2q23-q24
    91,12q13
    92,2q22.3
    93,3p22
    94,12q11-q14
    95,3p21.1
    97,14q24.3
    98,2p16.2 
    

提交回复
热议问题