I can kinda duplicate your error with the following

use 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 }
Result
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.
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.