Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: refering to 1 shared hash from another

by ISAI student (Scribe)
on Apr 24, 2013 at 12:06 UTC ( [id://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...

Replies are listed 'Best First'.
Re^4: refering to 1 shared hash from another
by Random_Walk (Prior) 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!
Re^4: refering to 1 shared hash from another
by Random_Walk (Prior) 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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-20 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found