Skip Menu |

This queue is for tickets about the Hash-Merge CPAN distribution.

Report information
The Basics
Id: 69872
Status: patched
Priority: 0/
Queue: Hash-Merge

People
Owner: Nobody in particular
Requestors: JBusco [...] nvidia.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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.

Subject: Re: [rt.cpan.org #69872] trouble using Hash::Merge
Date: Thu, 28 Jul 2011 21:12:29 -0500
To: bug-Hash-Merge [...] rt.cpan.org
From: Dan Muey <webmaster [...] simplemood.com>
'step1 has a value so it's not being replaced, its just merged in so it is remains the same reference, Data::Dumper uses $VAR->… to show it is a reference to the that spot elsewhere in the structure HTH! On Jul 28, 2011, at 7:45 PM, John Busco via RT wrote: Show quoted text
> Thu Jul 28 20:45:34 2011: Request 69872 was acted upon. > Transaction: Ticket created by JBusco@nvidia.com > Queue: Hash-Merge > Subject: trouble using Hash::Merge > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: JBusco@nvidia.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=69872 > > > > 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. > ----------------------------------------------------------------------------------- > > <testHashMerge.pl>
Subject: RE: [rt.cpan.org #69872] trouble using Hash::Merge
Date: Thu, 28 Jul 2011 19:28:50 -0700
To: "bug-Hash-Merge [...] rt.cpan.org" <bug-Hash-Merge [...] rt.cpan.org>
From: John Busco <JBusco [...] nvidia.com>
Thanks for helping me understand. The documentation says that "By default, the data passed to the merge function will be cloned using the Clone module;" (but there's also a Caveat that I don't completely understand). Should the merge completely (deeply) copy the input hashes, so there shouldn’t cross-references like this? Regards, John Show quoted text
-----Original Message----- From: SimpleMood Webmaster via RT [mailto:bug-Hash-Merge@rt.cpan.org] Sent: Thursday, July 28, 2011 7:11 PM To: John Busco Subject: Re: [rt.cpan.org #69872] trouble using Hash::Merge <URL: https://rt.cpan.org/Ticket/Display.html?id=69872 > 'step1 has a value so it's not being replaced, its just merged in so it is remains the same reference, Data::Dumper uses $VAR->… to show it is a reference to the that spot elsewhere in the structure HTH! ----------------------------------------------------------------------------------- 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. -----------------------------------------------------------------------------------
Subject: Re: [rt.cpan.org #69872] trouble using Hash::Merge
Date: Fri, 29 Jul 2011 12:35:49 -0500
To: bug-Hash-Merge [...] rt.cpan.org
From: Dan Muey <webmaster [...] simplemood.com>
On Jul 28, 2011, at 9:28 PM, John Busco via RT wrote: Show quoted text
> Queue: Hash-Merge > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=69872 > > > Thanks for helping me understand. The documentation says that "By default, the data passed to the merge function will be cloned using the Clone module;" (but there's also a Caveat that I don't completely understand). > > Should the merge completely (deeply) copy the input hashes, so there shouldn’t cross-references like this?
Hash::Merge 0.12 Clone 0.31 Perl 5.10.0 Hmm, you're right the cloning doesn't seem to be happening: perl -MHash::Merge -MData::Dumper -e 'Hash::Merge::set_clone_behavior(1);print Dumper({bar=>\@ARGV},{foo=>\@ARGV});' a b perl -MHash::Merge -MData::Dumper -e 'Hash::Merge::set_clone_behavior(0);print Dumper({bar=>\@ARGV},{foo=>\@ARGV});' a b but what its supposed to be doing under the hood works as expected: perl -MClone -MData::Dumper -e 'print Dumper({bar=>\@ARGV},{foo=>Clone::clone(\@ARGV)});' a b perl -MStorable -MData::Dumper -e 'print Dumper({bar=>\@ARGV},{foo=>Storable::dclone(\@ARGV)});' a b Note: I didn't try Clone::PP because its not on my laptop: perl -MClone::PP -MData::Dumper -e 'print Dumper({bar=>\@ARGV},{foo=>Clone::PP::clone(\@ARGV)});' a b I'll look into it further when I get some time, thanks
This has been patched upstream with commit 68b0415128a1d92310030cf2e6ca73bf6b7dd7c3. Fix for not dereferencing in a hash with depth greater 1 when using Clone or Clone::PP. Without passing the depth of the hashes (which was simply wrong anyway) the results are the same as if using Storable::dclone.