I'm actually just using this as a simplistic example, and it's a very simple example, which as you pointed out has a simpler alternative.
What I am trying to obtain is an explanation as to how hashes can be passed to a subroutine, populated and used within a subroutine, and used external to the subroutine with the data from the subroutine. Specifically, the line: ${%{$hash}}{$key} = $value; ^^^^^^^^^^^ This is the part I am not 100% clear on. R >From: "Jos I. Boumans" <[EMAIL PROTECTED]> >To: "Ross Howard" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> >Subject: Re: symbolic reference of hashes in subroutines >Date: Thu, 18 Oct 2001 15:49:21 +0200 > >i must be missing the point, but why are you using prototyped subroutines >to >populate a hash ref? > >what's wrong with: > >my $href = { > foo => 'quux', > bar => [ qw( bleh yuck) ], >}; > >or > >$href->{'baz'} = { foo => 'bar' } > >? > >regards, >Jos > >----- Original Message ----- >From: "Ross Howard" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Thursday, October 18, 2001 3:33 PM >Subject: symbolic reference of hashes in subroutines > > > > I figured this one out using the camel book and brute force methods. >But >if > > anyone could shed some light on symbolic references of the hash arrays I > > would appreciate it. > > > > Specifically, in the subroutine below populate_hash(), the line: > > ${%{$hash}}{$key} = $value; > > Seems kind of ugly saying heres a reference, really it's a hash, go >ahead > > and put a new key/value pair in, cause I know it's a hash. > > > > Is this the correct way of doing this? > > > > Thanks in advance, > > Ross > > > > #!/usr/local/bin/perl -w > > > > # Undefining the variables to be used as hash array > > undef $hash1; > > undef $hash2; > > > > # Insertting some values just to start things off > > $hash1{KEY0} = "value0"; > > $hash2{DOWAP} = "DOWAH"; > > > > # Populating each hash with more values using a subroutine > > populate_hash (\%hash1, "HEY1", "value1"); > > populate_hash (\%hash2, "HUMM", "HAH"); > > > > # Outputting the hash contents for first array > > foreach $key (keys %hash1) { > > print "hash1 $key -> $hash1{$key}\n"; > > } > > > > # Outputting the hash contents for second array > > foreach $key (keys %hash2) { > > print "hash2 $key -> $hash2{$key}\n"; > > } > > > > exit; > > > > # Simple subroutine to populate a passed hash array with values > > sub populate_hash ($$\%) { > > my $hash = $_[0]; > > my $key = $_[1]; > > my $value = $_[2]; > > > > ${%{$hash}}{$key} = $value; > > } > > > > > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at >http://explorer.msn.com/intl.asp > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]