- 论坛徽章:
- 0
|
这个省内存
- #!/usr/bin/perl -w
- use strict;
- my (@temp,@subtemp,@t,$ref1,$aa,$bb,$tt);
- $ref1 = \@temp;
- $tt = "";
- sub so {
- (split /[ \t]+/,$b)[1] <=> (split /[ \t]+/,$a)[1];
- }
- sub sortid{
- @subtemp = sort so @{$_[0]};
- $bb=1000;
- for(my $i=0;$i<=$#subtemp;$i++){
- @t = split /[ \t]+/,$subtemp[$i];
- $aa = @subtemp - $i;
- $bb = $aa if($t[1] == $t[3]);
- $subtemp[$i] =~ s/(^\d+\D+)(\d+)(.*)/$1$aa$3/ ;
- }
- for(my $i=0;$i<=$#subtemp;$i++){
- @t = split /[ \t]+/,$subtemp[$i];
- $subtemp[$i] =~ s/(^\d+\D)(\d+)(.*)/${1}0$3/ if ($t[1] == $bb);
- if ($t[1] > $bb){
- $t[1]--;
- $subtemp[$i] =~ s/(^\d+\D)(\d+)(.*)/${1}$t[1]$3/;
- }
- }
- }
- while (<>){
- chomp;
- my @line = split /[ \t]+/,$_;
- if($tt eq ""){
- push @temp,"@line" ;
- $tt = $line[0] ;
- next;
- }
- if($line[0] != $tt){
- sortid $ref1;
- foreach (@subtemp){
- print $_,"\n";
- }
- @temp =();
- push @temp,"@line";
- $tt = $line[0];
- next;
- }
- push @temp,"@line" ;
- $tt = $line[0] ;
- }
- sortid $ref1;
- foreach (@subtemp){
- print $_,"\n";
- }
复制代码 |
|