I would like to modify (grow) a hash of hashes iteratively within a loop through a subroutine and in the end print what's stored in the hash. To do this I am passing a reference to the hash to the subroutine - at least I thought so. However, I get the error "Global symbol "%misfits" requires explicit package name at ...". This is the code that I can't get to work:
Any help would be greatly appreciated.#Main my @whole_world = (); my $misfits = {}; # the reference foreach my $individual (@whole_world) { ($ok_ones, $misfits) = find_misfits(\@whole_world, $misfits); } print_misfits($misfits); # sub sub find_misfits { my ($whole_world, $misfits) = @_; my %candidates = (); # do stuff to find the misfits, ie compare the genetic setup of in +dividuals # add individuals that don't fit to $misfits $misfits{$stand}{$mother}{$offspring} = {%{$candidate{$stand}{ +$mother}{$offspring}}}; return ($misfits, some more structures); }
In reply to Growing a Hash of Hashes via its reference by Henri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |