This is one of those occasions when the intelligence in one module (Storable) combines with the incompleteness of another (threads::shared), to produce a mess.
Your JSON cloning mechanism is overkill though. A simple dumb clone() does the trick:
#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 1000; use threads; use threads::shared; use Storable qw[ store retrieve ]; sub clone { my $ref = shift; ref( $ref ) or return $ref; ref( $ref ) eq 'SCALAR' and return \(''.$$ref); ref( $ref ) eq 'HASH' and return { map+( $_, clone( $ref->{$_} )), keys %{ $ref } } +; ref( $ref ) eq 'ARRAY' and return [ map clone( $ref->[$_] ) , 0 .. $#{ $ref } ] +; die; } my %hash : shared = ( letters => shared_clone( { 'a'..'z' } ), numbers => shared_clone( { 1 .. 100 } ), ); store clone( \%hash ), "$0.bin"; my $retrieved :shared = shared_clone( retrieve "$0.bin" ); pp $retrieved;
In reply to Re: unable to store shared hash with Storable
by BrowserUk
in thread unable to store shared hash with Storable
by traceyfreitas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |