perl error: 'use of uninitialized value in concatenation (.) or string' using hash -


i have tab-delimited file: abc.txt. 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 creating parser takes abc.txt , 2 other files input , parses files calling different subroutines package: utility.pm

the subroutine parse abc.txt defined in package, utility.pm goes follows:

use strict;  sub readblast{  $filename = shift; %hash; %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 parser.pl script, uses hash follows:

my %blast=&utility::readblast($argv[2]); $mrna(keys %{ $featurehash{$scaffold}{$gene}}){ $desc = $blast{$mrna}; } 

here $featurehash hash made file. , $mrna has key values of file abc.txt.

but output of $desc blank , getting error:

use of uninitialized value $desc in concatenation (.) or string @ parser.pl 

what wrong my $desc = $blast{$mrna}; , why won't store 2nd column of abc.txt?

the following guards against trailing blank lines , possible non-tab separators (by using split limit):

#!/usr/bin/env perl  package my::utility;  use strict; use warnings;  sub read_blast {     $fh = shift;      %hash;      while (my $line = <$fh>) {         chomp $line;         last unless $line =~ /\s/;         ($key, $value) = split ' ', $line, 2;         $hash{ $key } = $value;     }      return \%hash; }  package main;  $blast = my::utility::read_blast(\*data); while (my ($k, $v) = each %$blast) {     print "'$k' => '$v'\n"; }  __data__ pytul_t015270   protein of unknown function pytul_t015269   protein of unknown function pytul_t015255   protein of unknown function pytul_t015297   protein of unknown function 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -