Here you're adding a key and scalar value to an existing shared hash:
$self->{$tag} = shared_clone($value);
Whereas here, you are attempting to autovivify an anonymous hash containing that key/value pair and assign a reference to it as the value of the key "ALWD_INFO" in the shared hash:
$self->{ALWD_INFO}{$tag} = shared_clone($value);
That reference to an unshared anonymous hash is an invalid value for a shared scalar.
Simple fix:
sub set_alwd_info { my ($self, $tag, $value) = @_; my %temp : shared = ( $tag => $value ); lock($self); $self->{ALWD_INFO} = \%temp; }
Update: However, if the sub will be called multiple times, with different key/value pairs and you want them to accumulate, then you'll only want to vivify the nested shared hash once:
sub set_alwd_info { my ($self, $tag, $value) = @_; if( not exists $self->{ALWD_INFO} or ref( $self->{ALWD_INFO} ) ne +'HASH' ) { my %temp : shared = ( $tag => shared_clone($value) ); lock($self); $self->{ALWD_INFO} = \%temp; } else { $self->{ALWD_INFO}{$tag} = shared_clone($value); } }
In reply to Re: Invalid value for shared scalar
by BrowserUk
in thread Invalid value for shared scalar
by SwaJime
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |