Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

refering to 1 shared hash from another

by ISAI student (Scribe)
on Apr 24, 2013 at 09:50 UTC ( #1030331=perlquestion: print w/ replies, xml ) Need Help??
ISAI student has asked for the wisdom of the Perl Monks concerning the following question:

Hello all. I am in the process of migrating a very messy code, partially working. In my work (I have done virtually no threaded work before) I came across a code that assigns a reference to a shared hash to a value in another shared hash. I added cluck to get the address info, and The value assigned is different than the value stored, if I read the output correctly Code is:
my %all_shary_for_subs :shared; my %sim_info :shared; $all_shary_for_subs{'%si +m_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" ) ;
The output of the code is the following (everything else is just use Carp, threads, threads::shared and comments)

the sim_info glob ref is:HASH(0x241bea8) at /edata/eng/ldagan/voodoo_from_1.1.7.b4/DesignLibs/ScriptLib/Generic/WMPerl/voodoo/voodoo_beta.pl line 81 And in the hash it is:HASH(0x2e42990) at /edata/eng/ldagan/voodoo_from_1.1.7.b4/DesignLibs/ScriptLib/Generic/WMPerl/voodoo/voodoo_beta.pl line 82

Why are the two addresses different?

Comment on refering to 1 shared hash from another
Download Code
Re: refering to 1 shared hash from another
by Random_Walk (Parson) on Apr 24, 2013 at 11:16 UTC

    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!

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-12-26 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (165 votes), past polls