I have a tab-delimited file: abc.txt. which has data like:
Pytul_T015270 Protein of unknown function
Pytul_T015269 Protein of unknown function
Pytul_T015255 Protein of unknown function
Pytul_T015297 Protein of unknown function
I am creating a parser which takes this abc.txt and 2 other files as input and parses the files by calling different subroutines from a package: utility.pm
The subroutine to parse abc.txt
is defined in my package, utility.pm
goes as follows:
use strict;
sub readblast{
my $fileName = shift;
my %hash;
my %geneNameHash;
open PRED, $fileName or die "Can't open file $!\n";
while (my $line=<PRED>) {
chomp $line;
#print $line,"\n";
(my $gene,my $desc) = split /\t/, $line;
$hash{$gene} = $desc;
}
close(PRED);
return %hash;
}
And my parser.pl script, which uses the hash is as follows:
my %blast=&utility::readblast($ARGV[2]);
for my $mRNA(keys %{ $featureHash{$scaffold}{$gene}}){
my $desc = $blast{$mRNA};
}
Here $featurehash
is another hash I made from another file. And $mRNA
has the key values of the file abc.txt
.
But output of $desc is blank and I am getting error:
Use of uninitialized value $desc in concatenation (.) or string at parser.pl
What is wrong with my $desc = $blast{$mRNA};
And why won't it store the 2nd column of abc.txt?
The following guards against trailing blank lines and possible non-tab separators (by using
split
with a limit):