use threads; use trheads::shared; ## Non-shared hash assigned some data: my %d = (1 .. 10 ); print Dumper \%d; $VAR1 = { '1' => 2, '3' => 4, '7' => 8, '9' => 10, '5' => 6 }; ## Share a reference to that hash and assign it to a shared scalar my $r:shared = share( %d ); ## And not only will the reference point to an empty hash print Dumper $r; $VAR1 = {}; ## But also the contents of the original hash will have been silently discarded print Dumper \%d; $VAR1 = {}; #### our %planets : shared; our $response = SomeClass::TCP_IP_Response->new(@some_arguments); [...] lock %planets; if (exists $planets{$some_id}) { lock $planets{$some_id}; $response->content($planets{$some_id}->{'data'}); $planets{$some_id}->{'atime'} = time; } else { my $data; [...] # read the serialized data from disk ## Assuming $data is a reference to a *simple*, *single-level* hash ## Copy the data into a shared equivalent; my %sharedHash :shared = %{ $data }; ## And then assign a reference to the *shared* copy. # my %el = ( 'data' => \%sharedHash, # 'atime' => time, # 'deleted' => 0, # 'modified' => 0 # ); ## But if you do this, *ALL THE CONTENTS OF %e1 WILL BE DISCARD* # $planets{$some_id} = share(%el); ## So make the local datastructure shared also my %el :shared = ( 'data' => \%sharedHash, 'atime' => time, 'deleted' => 0, 'modified' => 0 ); ## Now you do not need to use shared() ## as a reference to a shared object is shared. $planets{$some_id} = \%el; }