- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2013-04-11 10:09 编辑
回复 16# sinian126
How about this to add "*" on miss item
use strict;
use warnings;
my %hLoc;
my @aKey = qw(AC ID FA TT BS);
# note: keyword can use one time only
my $sCnt = 0;
$hLoc{$_}=$sCnt++ foreach(@aKey);
my $sFin = "lizi.txt";
open(FHin, "<", $sFin) or die "can't open $sFin\n";
my @aItem = ("*") x scalar(@aKey);
my $sItem = "";
while(<FHin>){
chomp;
if(m|^//|){
printf("%s\n", join("\t",@aItem));
@aItem = ("*") x scalar(@aKey);
$sItem = "";
next;
}
if(m/^XX/){
next;
}
my($sKey, $sData) = split(/\s+/,$_,2);
if(exists $hLoc{$sKey}){
#print "***get '$sKey', '$sData' for location $hLoc{$sKey}\n";
if($aItem[$hLoc{$sKey}] eq "*"){
$aItem[$hLoc{$sKey}] = $sData;
}
else{
$aItem[$hLoc{$sKey}] .= $sData;
}
}
}
--- output ------------
T00001 T00001 AAF * R02116; ...
T00002 T00002 ACE2p * R24013; ...
T00003 T00003 AS-C T3 * R03719; ...
|
|