in reply to refering to 1 shared hash from another

This works for me

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" )

Output:

the sim_info glob ref is:HASH(0x94b194) at C:\Documents and Settings\1161732\Perltest\scratch.pl line 9. And in the hash it is:HASH(0x94b194) at C:\Documents and Settings\1161732\Perltest\scratch.pl line 10.

Where is the rest of your code? This bit is missing the use so I gues it is a fragment pulled from something larger. Can you please post running code that shoes the behaviour you are seeing?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: refering to 1 shared hash from another
by space_monk (Chaplain) on Apr 24, 2013 at 11:26 UTC

    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
      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!