Dlamini has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
Is there an idiomatic way to add key/value pairs to a hash of anonymous hashes? For example, if I already have:
my %hoh; $hoh{element1} = {start => 1, middle => 5};
but then I want to add an end => 10 to the same anonymous hash without replacing what's already there. I guess the problem is that the hash, being anonymous, doesn't have a name through which I can access it (other than with keys %hoh -- or does it?). So I can extract the anonymous hash to the top level, add to it, then replace what used to be there like so:
but I was wondering if there is a better, more standard, idiomatic way to do this?my %temphash = %{$hoh{element1}}; $temphash{end} = 10; $hoh{element1} = \%temphash;
Thanks in advance...
Dlamini
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Adding to hash of hashes
by 2teez (Vicar) on Aug 24, 2012 at 23:56 UTC | |
by AnomalousMonk (Archbishop) on Aug 25, 2012 at 04:45 UTC | |
by Dlamini (Novice) on Aug 25, 2012 at 02:55 UTC | |
Re: Adding to hash of hashes
by Anonymous Monk on Aug 25, 2012 at 00:15 UTC | |
Re: Adding to hash of hashes
by Anonymous Monk on Aug 25, 2012 at 07:12 UTC |
Back to
Seekers of Perl Wisdom