level 1
男怪_奶呢然
楼主
大神,看到您解决了很多perl难题,我这边也被难住了,脑壳快折腾坏了,大神帮个忙吧
perl代码:
use strict;
use warnings;
my %hash=();
open(RF,"ann.txt") or die $!;
while(my $line=<RF>)
{
chomp($line);
my @arr=split(/\t/,$line);
$hash{$arr[0]}=$arr[1];
}
close(RF);
open(RF,"input.txt") or die $!;
open(WF,">out.txt") or die $!;
while(my $line=<RF>){
chomp($line);
if($.==1){
print WF "$line\tSymbol\n";
}
my @arr=split(/\t/,$line);
if(exists $hash{$arr[0]}){
print WF "$line\t$hash{$arr[0]}\n";
}
elsif(exists $hash{$arr[11]}){
print WF "$line\t$hash{$arr[11]}\n";
}
elsif(exists $hash{$arr[13]}){
print WF "$line\t$hash{$arr[13]}\n";
}
else{
}
}
close(WF);
close(WF);
运行后报错:C:\Users\girlc\Desktop\premature ovarian failure\Human Growth Hormone>perl addSymbol.pl
Use of uninitialized value $arr[11] in exists at addSymbol.pl line 28, <RF> line 2.
Use of uninitialized value $arr[13] in exists at addSymbol.pl line 31, <RF> line 2.
等等,后面还有很多行,请大神赐教,
2021年06月07日 09点06分
1
perl代码:
use strict;
use warnings;
my %hash=();
open(RF,"ann.txt") or die $!;
while(my $line=<RF>)
{
chomp($line);
my @arr=split(/\t/,$line);
$hash{$arr[0]}=$arr[1];
}
close(RF);
open(RF,"input.txt") or die $!;
open(WF,">out.txt") or die $!;
while(my $line=<RF>){
chomp($line);
if($.==1){
print WF "$line\tSymbol\n";
}
my @arr=split(/\t/,$line);
if(exists $hash{$arr[0]}){
print WF "$line\t$hash{$arr[0]}\n";
}
elsif(exists $hash{$arr[11]}){
print WF "$line\t$hash{$arr[11]}\n";
}
elsif(exists $hash{$arr[13]}){
print WF "$line\t$hash{$arr[13]}\n";
}
else{
}
}
close(WF);
close(WF);
运行后报错:C:\Users\girlc\Desktop\premature ovarian failure\Human Growth Hormone>perl addSymbol.pl
Use of uninitialized value $arr[11] in exists at addSymbol.pl line 28, <RF> line 2.
Use of uninitialized value $arr[13] in exists at addSymbol.pl line 31, <RF> line 2.
等等,后面还有很多行,请大神赐教,