views:

534

answers:

2
+2  A: 

I think it's this line:

my (%hash) = %{$_[0]};

You're passing in a reference, but this statement is making a copy of your hash. All additions you make in singlegene are then lost when you return.

Leave it as a hash reference and it should work.

PS - Data::Dumper is your friend when large data structures are not behaving as expected. I'd sprinkle a few of these in your code...

use Data::Dumper; print Dumper \%genomehash;

jmanning2k
+4  A: 

You are passing a reference to %genomehits to the function singlegene, and then copying it into a new hash when you do my (%hash) = %{$_[0]};. You then add values to %hash which goes away at the end of the function.

To fix it, use the reference directly with arrow notation. E.g.

my $hash = $_[0];
...
$hash->{$key} = yadda yadda;
friedo
thanks a lot; I was using references like this before but perl told me this was deprecated semantics. Never listen to the compiler!
Overflown
I'm highly suprised perl told you that. As far as I know it's not deprecated at all.
Jeremy Wall
$hash->{$key} == ${$hash}{$key} == $$hash{$key}; some people like #2 or #3 more than #1. #1 is the most common, but #3 has the advantage of being easily interpolated into strings.
ephemient