在Perl正则表达式编译中使用未初始化值
我有以下代码:在Perl正则表达式编译中使用未初始化值,perl,Perl,我有以下代码: use strict; use warnings; use IO::File; use Bio::SeqIO; my ($file1) = $ARGV[0]; my ($file2) = $ARGV[1]; my $fh1 = IO::File->new("$file1")|| die "Can not create filehandle"; my $fh2 = IO::File->new("$file2")|| die "Can not create fileh
use strict;
use warnings;
use IO::File;
use Bio::SeqIO;
my ($file1) = $ARGV[0];
my ($file2) = $ARGV[1];
my $fh1 = IO::File->new("$file1")|| die "Can not create filehandle";
my $fh2 = IO::File->new("$file2")|| die "Can not create filehandle";
my @aligned_array = ();
while(my $line1 = $fh1->getline){
chomp($line1);
if (($line1 =~ /^match/)||($line1 =~ /^-/)) {
next;
}
else {
my @line_array = split(/\s+/, $line1);
push(@aligned_array, $line_array[9]);
}
}
my $fio1 = IO::File->new("> chimeric_contigs.txt")|| die "Can not create filehandle";
while(my $line2 = $fh2->getline) {
my $count = 0;
chomp($line2);
for my $aligned (@aligned_array) {
# print $line2.$aligned."\n";
if ($line2 =~ m/$aligned/) {
$count++;
}
}
if ($count >= 2) {
print $fio1 $line2."\n";
}
}
$fio1->close;
我一直都犯同样的错误
在/gscuser/rfujiwar/bin/find\u chimeric\u contigs\u blat.pl第41行的regexp编译中使用未初始化值
这是第41行:if($line2=~m/$aligned/){
$line2和$aligned都是定义的,因为我可以毫无问题地打印它们。请帮助。(从评论中转载,因为这最终解决了问题)都是
@aligned\u array
定义的所有元素吗?在第41行之前放入下一行,除非定义了$aligned;
如果$line\u array[9]将其推送到@aligned_数组时未初始化:
换句话说,split在$line1中找不到十个空格分隔的元素(并且$#line_数组小于九个)。因此,不要将此行添加到数组中,或在$file1中修复输入。打印它们时会得到什么?我期望的正确字符串Contig0.3Contig872.1 Contig0.3Contig872.1 Contig0.3Contig872.1 Contig0.3Contig872.1 Contig0.3contig0.3Contig873.1等…这是取消注释的结果#print$line2.$aligned.“\n”“
@aligned_array
的所有元素都定义好了吗?在第41行之前放入下一行,除非定义了$aligned;
。谢谢Jack Maney
my @line_array = split(/\s+/, $line1);
push(@aligned_array, $line_array[9]);