[Za-pm] passing HoH refs to a sub
Lee Shane Engel(Cont-Gert)
lee.engel at vcontractor.co.za
Tue Jul 8 06:05:37 CDT 2003
dereferencing hash of hashes you do like this:
$$name_of_hash{'key1'}->{'key_of_inner_hash'};
I could be mistaken.
Cheers,
Lee
-----Original Message-----
From: za-pm-bounces at mail.pm.org [mailto:za-pm-bounces at mail.pm.org]On Behalf Of Spike
Sent: 08 July 2003 12:58
To: Za-pm at mail.pm.org
Subject: [Za-pm] passing HoH refs to a sub
I have a hash of hashes and want to pass a reference to that HoH to a sub routine (which we call 'print_it' for this example).
So I go:-
<cut>
print_it(\%HoH);
<cut>
Now my problem comes when I want to de-reference the HoH values:-
<cut>
sub print_it
{
my $hash_ref = shift;
foreach $key (keys %$hash_ref)
{
print "$key: ";
# up to here all is well!
# but I can't get the syntax to access the 'child' hash values
# This does not work:-
foreach $code ( keys %{ %$hash_ref{$key} } )
{
# print "$code = %$hash_ref{$key}{$code} ";
}
# the problem is in the 'keys %{ %$hash_ref{$key}' bit.
<cut>
Using the hash directly the following would be valid:-
foreach $key (keys %HoH)
{
print "$key: ";
foreach $code ( keys %{ $HoH{$key} } )
{
print "$code = $HoH{$key}{$code} ";
}
print "\n";
}
Any ideas on the correct syntax??
Spike Hodge
UNIX Programmer
M-Web Technology
021 596 8496
082 901 5265
Click here and make M-Web your homepage
http://homepage.mweb.co.za <http://homepage.mweb.co.za/>
This e-mail is sent on the Terms and Conditions that can be accessed by Clicking on this link http://www.vodacom.net/legal/email.asp "
More information about the Za-pm
mailing list