我认为这会对你有所帮助,如果有任何澄清让我知道:
输入文件是:
12345|1|-|-|-
12346|-|2|-|4
12347|-|-|3|-
12348|5|-|-|-
12349|-|6|-|8
12350|-|-|7|-
脚本
use strict;
use warnings;
sub processor{
(my @tmp )=@_;
my @inner;
shift(@tmp);
foreach my $element(@tmp){
$_=$element;
if((m/[0-9]/)){
push(@inner,$element);
}
}
return @inner;
}
open(INFILE,"infile.dat") or die "$!";
open(OFILE,">outfile.dat") or die "$!";
my @ecollector;
my $keyVal;
my $counter;
while(<INFILE>){
chomp($_);
my @tmp=split('\|',$_);
if(($. % 3) ne 0){
if(($. % 3) eq 2){ $keyVal=$tmp[0];}
push(@ecollector,processor(@tmp));
}
else{
push(@ecollector,processor(@tmp));
print OFILE "$keyVal\t".join("\t",sort(@ecollector))."\n";
@ecollector=();
}
}
close(INFILE);
close(OFILE);