On Mon, Nov 10, 2008 at 3:52 PM, Travis Thornhill <[EMAIL PROTECTED] > 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? > > Thanks, > - Travis > > > Hi Travis, The problem you are facing is that $main_hash{'sub_hash'} does not return a hash at all but a reference. Which is exactly what perl is telling you. You can simply tell perl that it should dereference the reference to a hash, you could do that like this: #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %hash = ( 1 => 'one', 2 => 'two', 3 => { 3.1 => 'three point one', 3.2 => 'three point two' }, 4 => 'four' ); my %hash_slice = %{$hash{3}}; print Dumper %hash_slice; Reagrds, Rob