SwaJime has asked for the wisdom of the Perl Monks concerning the following question:
Hello again :-)
Hopefully this is a simple problem ... I'd like some help getting this second method to work.
I am working with a class that contains the following method:
# Adds fields to a shared object sub set { my ($self, $tag, $value) = @_; lock($self); $self->{$tag} = shared_clone($value); }
I'm trying to add a second method similar to the first:
# Adds sub fields to a shared object sub set_alwd_info { my ($self, $tag, $value) = @_; lock($self); 43: $self->{ALWD_INFO}{$tag} = shared_clone($value); }
But I'm getting this error when I try to run it:
Invalid value for shared scalar at ./thread line 32.Full sample code:
#!/usr/bin/perl # package ALWD::Cows; use strict; use warnings; use threads; use threads::shared qw(share is_shared shared_clone); # Constructor sub new { my $class = shift; share(my %self); # $self{ALWD_INFO} = {}; # ... ... ... my $self = bless(\%self, $class); return $self; } # Adds fields to a shared object sub set { my ($self, $tag, $value) = @_; lock($self); $self->{$tag} = shared_clone($value); } # Adds sub fields to a shared object sub set_alwd_info { my ($self, $tag, $value) = @_; lock($self); $self->{ALWD_INFO}{$tag} = shared_clone($value); } package main; my $sample = ALWD::Cows->new(); $sample->set("Key1", "Value1"); $sample->set_alwd_info("Key2", "Value2");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Invalid value for shared scalar
by BrowserUk (Patriarch) on Feb 03, 2016 at 19:56 UTC | |
|
Re: Invalid value for shared scalar
by SwaJime (Scribe) on Feb 03, 2016 at 20:49 UTC | |
|
Re: Invalid value for shared scalar
by poj (Abbot) on Feb 03, 2016 at 20:14 UTC |