in reply to Re^3: Threading: Invalid value for shared scalar
in thread Threading: Invalid value for shared scalar
But in the second example this
looks like an superficial assignment of $abc{ $parent }{ $child } since immediately thereafter the reference \%c is overwritten by a scalar. For two levels of hashing two shared hashes should be enough (%abc and %p).... unless ( exists $abc{$parent}{$child} ) { my %c : shared; $abc{$parent}{$child}=\%c; } ...
So for this example the following minimal version should work as well:
For all Perl people who got a bit confused by the example code like I was...# shared hash version. my %abc : shared ; my @parents = qw( a b c ); my @children = qw( 1 2 3 4 ); for my $parent ( @parents ) { unless (exists $abc{$parent}) { my %p : shared; $abc{ $parent } = \%p; } for my $child ( @children ) { $abc{ $parent }{ $child } = 1; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Threading: Invalid value for shared scalar
by BrowserUk (Patriarch) on Jul 03, 2015 at 12:42 UTC |