我有一个程序可以在解析 FASTA 文件时创建一个哈希数组。这是我的代码
use strict;
use warnings;
my $docName = "A_gen.txt";
my $alleleCount = 0;
my $flag = 1;
my $tempSequence;
my @tempHeader;
my @arrayOfHashes = ();
my $fastaDoc = open(my $FH, '<', $docName);
my @fileArray = <$FH>;
for (my $i = 0; $i <= $#fileArray; $i++) {
if ($fileArray[$i] =~ m/>/) { # creates a header for the hashes
$flag = 0;
$fileArray[$i] =~ s/>//;
$alleleCount++;
@tempHeader = split / /, $fileArray[$i];
pop(@tempHeader); # removes the pointless bp
for (my $j = 0; $j <= scalar(@tempHeader)-1; $j++) {
print $tempHeader[$j];
if ($j < scalar(@tempHeader)-1) {
print " : "};
if ($j == scalar(@tempHeader) - 1) {
print "\n";
};
}
}
# push(@arrayOfHashes, "$i");
if ($fileArray[$i++] =~ m/>/) { # goes to next line
push(@arrayOfHashes, {
id => $tempHeader[0],
hla => $tempHeader[1],
bpCount => $tempHeader[2],
sequence => $tempSequence
});
print $arrayOfHashes[0]{id};
@tempHeader = ();
$tempSequence = "";
}
$i--; # puts i back to the current line
if ($flag == 1) {
$tempSequence = $tempSequence.$fileArray[$i];
}
}
print $arrayOfHashes[0]{id};
print "\n";
print $alleleCount."\n";
print $#fileArray +1;
我的问题是当线路
打印 $arrayOfHashes[0]{id};
被调用,我收到一条错误消息
在 fasta_tie.pl 第 47 行第 6670 行的打印中使用未初始化的值。
你会在上面的代码中看到我注释掉了一行,上面写着
推(@arrayOfHashes,“$i”);
因为我想确保哈希有效。此外,数据以所需的格式正确打印。看起来像这样
HLA:HLA00127:A*74:01:2918