Reputation: 3543
I have a hash of Class::Struct
, how do I clone it (deep copy)? Class::Struct
does not provide a clone
or copy
method and manually copying the internals of Class::Struct
would be hard.
my %a = ();
$a{k} = MyStruct->new;
my %b = ... ?
Upvotes: 2
Views: 142
Reputation: 3543
The Storable
module provides a dclone
function that is able to deep-copy the hash and the Class::Struct
contents.
use Storable qw/dclone/;
my %a = ();
$a{k} = MyStruct->new;
my %b = %{dclone(\%a)};
Upvotes: 3