Speed_Freak has asked for the wisdom of the Perl Monks concerning the following question:
I've been piecing this together for a while, but I'm getting stuck again. Does anyone have an idea how to merge a hash with itself?
I'm probably phrasing that wrong, but I have used Paralell:ForkManager to fork an if loop to utilize 40 threads. That if loop then creates a nested hash structure that needs to be returned. I use nfreeze from Storable to serialize the data, then I return that reference to the parent. I then dereference and thaw.
#dumper of thawed data $VAR44123 = '511879'; $VAR44124 = { 'file3232.ext' => { 'e' => 0, 'k' => '0.0031', 'i' => '26.9', 'j' => '33.0' } }; $VAR44125 = '739569'; $VAR44126 = { 'file3232.ext' => { 'e' => 0, 'k' => '0.1040', 'i' => '26.7', 'j' => '14.6' } };
Before the forking happens, I define the parent hash as %parent = ();
And I need to push each data structure into that parent hash, but I need them to merge.
The ending data structure will have the leftmost structure staying, but adding additional files to the middle structure, and corresponding datasets from the right side for each of those added files.
The problem I'm having is that I can't figure out how to use Hash::Merge to merge the parent hash with each returned hash from the forks.
I was thinking something like %parent = merge( \%parent, \%returned); but that currently gives me errors about having Reference found where even-sized list expected... but in one of my earlier iterations I didn't have errors, but that merge caused the script to go to one thread and hang until it ran out of memory.
Am I barking up the right tree here? Or should I be using something else to merge a structure like this?
cliff notes: I need to start with an empty hash, and then return multidimensional hashes from forks and compile them into the parent hash as each fork returns.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Merging multidimensional hashes from forks to parent hash
by choroba (Cardinal) on Jul 12, 2018 at 18:40 UTC | |
|
Re: Merging multidimensional hashes from forks to parent hash
by atcroft (Abbot) on Jul 12, 2018 at 20:01 UTC | |
|
Re: Merging multidimensional hashes from forks to parent hash
by tybalt89 (Monsignor) on Jul 12, 2018 at 18:01 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |