tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:

I would like to pass an reference to an internal hash in a hash of hashes to a subrutine... In a similar fashion to this: (code is corrupt)
#!/usr/bin/perl -w use strict; my %hoh; $hoh{'A'}{1}=100; $hoh{'A'}{2}=200; $hoh{'A'}{3}=300; $hoh{'A'}{4}=400; $hoh{'B'}{10}=500; $hoh{'B'}{20}=600; $hoh{'B'}{30}=700; $hoh{'B'}{40}=800; rutine(\%{$hoh{'A'}}): sub rutine { my ($hoh_slice_ref)=@_; ... }
How should this be done properly? Thank you for your help.

Replies are listed 'Best First'.
Re: Pass reference to internal hash?
by ikegami (Patriarch) on Nov 04, 2006 at 22:59 UTC

    The following suffices:

    rutine($hoh{'A'});

    Remember, $hoh{'A'}{1} is actually short for $hoh{'A'}->{1}. %hoh is a hash of references (to hashes).

    I wouldn't call it a HoH slice, though. It's simply a reference to a hash.

      Yes ofcourse thank you.