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

Re: Re: Re: threads::shared hash

by BrowserUk (Patriarch)
on Mar 27, 2004 at 01:30 UTC ( [id://340185]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: threads::shared hash
in thread threads::shared hash

Unfortunately, autovivification doesn't auto-share, so you have to manually create shared elements.

#! perl -slw use strict; use threads; use threads::shared; use Data::Dumper; my %hash : shared; my $var = 'hello'; $hash{ foo } = &share( {} ); $hash{ foo }{ bleh } = 'test'; $hash{ $var } = &share( {} ); $hash{ $var }{ foo } = 'test'; print Dumper \%hash; __END__ P:\test>test $VAR1 = { 'foo' => { 'bleh' => 'test' }, 'hello' => { 'foo' => 'test' } };

Note: The &shared( {} ); syntax is required. See threads::shared for details.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re: Re: threads::shared hash
by fxmakers (Friar) on Mar 27, 2004 at 02:28 UTC
    Thanks a lot!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found