Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: refering to 1 shared hash from another

by space_monk (Chaplain)
on Apr 24, 2013 at 11:26 UTC ( #1030362=note: print w/ replies, xml ) Need Help??


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

Same with me (on Cygwin though). This is a bit of a "Me too!" response, but thought knowing that the problem is not repeatable would be helpful.

If any of my proposed solutions have minor errors, it's because I don't waste my genius on trivial matters. :-P


Comment on Re^2: refering to 1 shared hash from another
Replies are listed 'Best First'.
Re^3: refering to 1 shared hash from another
by ISAI student (Scribe) on Apr 24, 2013 at 12:06 UTC
    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...

      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!

      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
Node Status?
node history
Node Type: note [id://1030362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-07-28 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls