HarshaHegde has asked for the wisdom of the Perl Monks concerning the following question:
I have a HoH reference like this:
I am trying to turn this HoH inside out. i.e., I am trying to get:$VAR1 = { 'FOO' => { 'TABLE_NAME' => 'FOO', 'TABLE_TYPE' => 'REFERENCE' }, 'BAR' => { 'TABLE_NAME' => 'BAR', 'TABLE_TYPE' => 'REFERENCE' }, 'BAZ' => { 'TABLE_NAME' => 'BAZ', 'TABLE_TYPE' => 'CUSTOMER' } };
The easiest option I can think of at this point is to create a HoA from the reference to the HoH. Something like:$VAR1 = { 'REFERENCE' => [ 'FOO', 'BAR' ], 'CUSTOMER' => 'BAZ' };
But this gives me the following error:my %HoA; foreach my $key (keys %$ref_to_HoH){ my $type = $ref_to_HoH->{$key}->{TABLE_TYPE}; if (exists $HoA{$type}){ push @{$HoA{$type}},$key; }else { $HoA{$type} = $key; } }
Can't use string ("FOO") as an ARRAY ref while "strict refs" in use at + .....
What am I doing wrong here? Greatly appreciate any help from the revered monks here.
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: error creating hash of array
by graff (Chancellor) on Nov 04, 2007 at 18:13 UTC | |
by HarshaHegde (Sexton) on Nov 04, 2007 at 18:23 UTC | |
|
Re: error creating hash of array
by mwah (Hermit) on Nov 04, 2007 at 18:39 UTC |