I can kinda duplicate your error with the following
Resultuse strict; use warnings; use Data::Dumper; my $indexfile = { 'GCTCAGGA' => '4', 'AGCGTAGC' => '5', 'TTCTGCCT' => '3', 'CATGCCTA' => '6', 'TCGCCTTA' => '1', 'GTAGAGAG' => '7', 'GCGTAAGA' => '13', 'TAGATCGC' => '9', 'CTAGTACG' => '2', 'CTAAGCCT' => '16', 'CTCTCTAT' => '10', 'ACTGCATA' => '14', 'AGAGTAGA' => '12', 'TATCCTCT' => '11', 'AAGGAGTA' => '15', 'CCTCTCTG' => '8' }; my $queryseq=''; for my $key (keys %$indexfile) {$queryseq.=$key;} print "First\n"; match_query($indexfile,$queryseq); print "second\n"; $indexfile->{a}=1; match_query($indexfile,$queryseq); sub match_query{ my $indexfile = shift; my $queryseq = shift; print Dumper($indexfile); my @match_count; for my $key (keys %$indexfile){ my $count; for(my $k=0; $k<length($key)-1; $k++){ my $k_nuc = substr $key,$k,2; for(my $i=0; $i<length($queryseq)-1; $i++){ my $i_nuc = substr $queryseq,$i,2; my $rel = $k-$i; if($k_nuc eq $i_nuc){ $count->{$rel} ||= 0; $count->{$rel} += 1; }else{ $count->{$rel} ||= 0; $count->{$rel} += 0; } } } my @array = sort{$b <=> $a} values %$count; my $max_count = shift @array; my $element; $element->{bar} = $key; $element->{max} = $max_count; push @match_count, $element; } my $result; @match_count = sort{$b ->{max} <=> $a->{max}} @match_count; #CODE +#FAILS HERE DOESNT LIKE ->{max} if($match_count[0]->{max} == $match_count[1]->{max}){ $result = 0; }elsif($match_count[0]->{max}>5){ my $called_bar = $match_count[0]->{bar}; $result = $indexfile->{$called_bar}; }else{ $result = 0; } return $result }
Notice the inclusion of use Data::Dumper; and print Dumper($indexfile);. Notice how in the second pass $indexfile has a "short key". I suspect that if you make the same mods to your program you will also notice a "short key". a short key bypasses for(my $k=0; $k<length($key)-1; $k++){ and so $count remains undef.First $VAR1 = { 'CTAGTACG' => '2', 'ACTGCATA' => '14', 'CTAAGCCT' => '16', 'CCTCTCTG' => '8', 'AGCGTAGC' => '5', 'GCGTAAGA' => '13', 'TCGCCTTA' => '1', 'AGAGTAGA' => '12', 'GCTCAGGA' => '4', 'TTCTGCCT' => '3', 'GTAGAGAG' => '7', 'CTCTCTAT' => '10', 'AAGGAGTA' => '15', 'CATGCCTA' => '6', 'TAGATCGC' => '9', 'TATCCTCT' => '11' }; second $VAR1 = { 'TCGCCTTA' => '1', 'AGAGTAGA' => '12', 'CTAAGCCT' => '16', 'CCTCTCTG' => '8', 'AGCGTAGC' => '5', 'GCGTAAGA' => '13', 'ACTGCATA' => '14', 'CTAGTACG' => '2', 'TATCCTCT' => '11', 'a' => 1, 'CATGCCTA' => '6', 'TAGATCGC' => '9', 'CTCTCTAT' => '10', 'AAGGAGTA' => '15', 'GTAGAGAG' => '7', 'TTCTGCCT' => '3', 'GCTCAGGA' => '4' }; Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66. Use of uninitialized value in numeric comparison (<=>) at 1194053.pl l +ine 66.
edit to add: an empty $queryseq also could produce the same kind of result.
In reply to Re: Help with function, count matches and store in hash & retrieve sorted
by huck
in thread Help with function, count matches and store in hash & retrieve sorted
by Pathogenomix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |