【发布时间】:2012-10-11 10:56:14
【问题描述】:
我正在尝试将两个值粘贴到一个字符串中。一个值是数组元素,另一个是 hashmapvalue。但我一直有这个错误:
Use of uninitialized value in concatenation (.) or string
at makeNewCSV.pl line 104, <$fh> line 2020.
这是我的代码:
use feature qq(say);
my @nodeIdArray;
my @sequenceArray;
my @completeLineArray;
my %fastaHash = ();
[...]
sub readCsv{#Reads the CSV and puts all the Node ID's in an array
my ($file) = @_;
my $nodeID = qr{\d+\,(\d+)};
open(my $fh, '<', $file) or die "Error while reading CSV: $!";
while(my $line = <$fh>){
if($line =~ $nodeID){
push(@nodeIdArray, $1);
}
}
close($fh);
searchFasta();
}
sub searchFasta{#Reads and searches the fasta file for contigs with a matching node ID
my ($file) = $ARGV[1];
my $fastaNodeID = qr{>NODE_(\d+)_LENGTH_\d+_COV_[\d.]+\n([ACTGN\n]+)};
my @matches;
open(my $fh, '<', $file) or die "Error while reading fasta: $!";
my @allLines = <$fh>;
my $makeString = join('', @allLines);
my $lineAsString = uc($makeString);
while($lineAsString =~ m/$fastaNodeID/g){
my $node_ID = $1;
my $sequence = $2;
$sequence =~ s/\n//;
$fastaHash{$node_ID} = $sequence;
}
close($fh);
pasteLines();
}
sub pasteLines{
my $fullLine = "";
my $file = $ARGV[0];
my @hashKeys = keys(%fastaHash);
my $index = 0;
my $numberOfRepeat = 0;
open(my $fh, '<', $file) or die "Error while reading CSV (2): $!";
my @allLines = <$fh>;
my $arrayLength = @allLines;
foreach my $line(@allLines){
chomp($line);
}
while($numberOfRepeat <= $arrayLength){
foreach my $key(@hashKeys){
if($key = $nodeIdArray[$index]){
no warnings qw(uninitialized); #DEBUG:
say qq(DEBUG: \$fastaHash{$key} = "$fastaHash{$key}");
say qq(DEBUG: \$fullLine = $allLines[$index] . "," . $fastaHash{$key};);
use warnings qw(uninitialized); #DEBUG:
$fullLine = $allLines[$index] . "," . $fastaHash{$key}; #This line here gives the problems
push(@completeLineArray, $fullLine);
$index++;
}
else{
$index++;
}
}
}
close($fh);
}
$index 用于循环遍历数组,@allLines 包含读取文件中的所有行。 (<$fh> 是我的文件句柄)。
2012 年 10 月 22 日编辑:我添加了整个代码以显示变量的生成位置
【问题讨论】:
-
好吧,要么列表项是
undef,要么哈希没有该值的键。我真的不明白我们如何能在这方面为您提供帮助。 -
David W. 在下面为您提供了一些很好的调试思路。如果您仍然遇到问题,则需要发布更多代码,因为问题不在这些行之外:显示设置
@allLines、$index、%fastaHash和$key的代码。 -
我刚刚发布了更多代码。我希望这有助于理解我的问题