Henri has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Growing a Hash of Hashes via its reference
by almut (Canon) on Feb 17, 2009 at 19:41 UTC | |
|
Re: Growing a Hash of Hashes via its reference
by Bloodnok (Vicar) on Feb 17, 2009 at 19:41 UTC | |
|
Re: Growing a Hash of Hashes via its reference
by toolic (Bishop) on Feb 17, 2009 at 19:35 UTC | |
|
Re: Growing a Hash of Hashes via its reference
by Henri (Novice) on Feb 17, 2009 at 20:02 UTC |