Travis Thornhill wrote: > > Is there such a thing? > > I'm trying to take a HoH and make a reference to a sub-part of the hash. > > This doesn't work: > > my %sub_hash = $main_hash{'sub_hash'}; > > I get the following error: > Reference found where even-sized list expected at ./my_buggy_program line 30. > > Any quick tips on how to reference and assign this sub-hash?
There is certainly such a thing as a hash slice, but I think it is probably not what you want here. A slice will let you extract multiple values from the hash simultaneously, something like my @subhashes = @main_hash{'key1', 'key2', 'key3'}; and it doesn't look to me like that's what you're trying to achieve. If you have a hash of hashes then $main_hash{'sub_hash'} is already a reference, as the error message has told you, so you should write my $subhash_ref = $main_hash{'sub_hash'}; after which you can access the subsidiary hash with constructs like foreach my $key (keys %$subhash_ref) { printf "%s => %s\n", $key, $subhash_ref->{$key}; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/