Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: refering to 1 shared hash from another

by ISAI student (Scribe)
on Apr 24, 2013 at 12:06 UTC ( #1030372=note: print w/ replies, xml ) Need Help??


in reply to Re^2: refering to 1 shared hash from another
in thread refering to 1 shared hash from another

Well, here is the code:

use strict ; use warnings; use Thread; use threads::shared; use Carp qw (cluck) ; my %all_shary_for_subs :shared; my %sim_info :shared; $all_shary_for_subs{'%sim_info'}=\%sim_info; cluck("the sim_info glob ref is:" . \%sim_info . "\n" ); cluck("And in the hash it is:" . $all_shary_for_subs{'%sim_info'} . "\ +n" );
Version is: This is perl, v5.10.0 built for x86_64-linux-thread-multi However, removing the  use Thread gives the correct results...


Comment on Re^3: refering to 1 shared hash from another
Select or Download Code
Re^4: refering to 1 shared hash from another
by Random_Walk (Parson) on Apr 24, 2013 at 12:26 UTC

    the Thread module is deprecated. Go for threads. Having said that I can add use threads; just fine, but I am seeing the mis-match whenever I use threads::shared;. It looks like threads::shared is making a copy of the hash

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
Re^4: refering to 1 shared hash from another
by Random_Walk (Parson) on Apr 24, 2013 at 12:46 UTC

    use strict ; use warnings; use threads; use threads::shared; use Data::Dumper; my %HoH :shared; my %hash :shared; $hash{pre_key} = "Before"; $HoH{hash}=\%hash; $hash{post_key} = "After"; if (\%hash eq $HoH{hash}) { print "OK\n"; } else { print "Copied, I suspect\n"; } print Data::Dumper->Dump ([\%hash], ["hash"]); print Data::Dumper->Dump ([$HoH{hash}], ["HoH"]); print "But looks like they still stay in sych\n
    Output
    Copied, I suspect $hash = { 'pre_key' => 'Before', 'post_key' => 'After' }; $HoH = { 'pre_key' => 'Before', 'post_key' => 'After' }; But looks like they still stay in sych

    Update

    I just read the docco for threads::shared and found this gem, which explains your issue:

    Using refaddr()) is unreliable for testing whether or not two shared references are equivalent (e.g., when testing for circular references). Use is_shared(), instead:

    There is more detail, and an example of the correct way to test in said docco

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-12-28 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls