Subject: | trouble using Hash::Merge |
Date: | Thu, 28 Jul 2011 17:45:20 -0700 |
To: | "bug-Hash-Merge [...] rt.cpan.org" <bug-Hash-Merge [...] rt.cpan.org> |
From: | John Busco <JBusco [...] nvidia.com> |
I'm trying to write a script to combine two sets of hash data structures and produce a master hash with all the combinations. I wonder if there is something I'm doing wrong here, or if the Hash::Merge package isn't working as expected. I don't want anyone spending much time debugging my code, but if you recognize what may be wrong, or have revealing questions for me, I'd appreciate it.
I attach a copy of the script. It loads my local copy of Hash::Merge<http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm> for now.
I have two Hash data structures that I want to merge (include the data structures from both in a new hash) and add as a new entry in a "master" hash table.
my $hash1A = {
'unit' => 'U1'
};
my $hash2 = {
'customize_node' => {
'step1' => {
'tool' => 'dc'
}
}
};
After merge, produces
$VAR1 = {
'unit' => 'U1',
'customize_node' => {
'step1' => {
'tool' => 'dc'
}
}
};
That looks good. Then, I insert this in to a "master hash" keyed by the unit name (U1):
$VAR1 = {
'U1' => {
'unit' => 'U1',
'customize_node' => {
'step1' => {
'tool' => 'dc'
}
}
}
};
That all looks fine. But when I create another merged hash from
my $hash1B = {
'unit' => 'U2'
};
And previous $hash2, though it looks fine by itself
$VAR1 = {
'unit' => 'U2',
'customize_node' => {
'step1' => {
'tool' => 'dc'
}
}
};
It gets "corrupted" when I insert it into the master hash:
$VAR1 = {
'U1' => {
'unit' => 'U1',
'customize_node' => {
'step1' => {
'tool' => 'dc'
}
}
},
'U2' => {
'unit' => 'U2',
'customize_node' => {
'step1' => $VAR1->{'U1'}{'customize_node'}{'step1'}
}
}
};
I don't understand this $VAR1 business being dumped out. It's like there's a circular reference. Is it some remnant of part of hash2? I thought Hash::Merge would create a new copy of the hash data structure.
Thanks for any ideas,
John
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Message body is not shown because it is too large.
Message body is not shown because sender requested not to inline it.