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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: threads::shared hash
by fxmakers (Friar) on Mar 27, 2004 at 02:28 UTC |