in reply to Unable to make shallow copy of Moo hash ref attribute
It sounds to me like you want a deep copy rather than a shallow one? That's what Storable's dclone does.
use warnings; use strict; use Data::Dump 'dd'; use Storable 'dclone'; my $hr = { foo => { bar => "quz" } }; my $deep = dclone($hr); $deep->{foo}{bar} = 'baz'; $deep->{x} = 'y'; dd $deep; # { foo => { bar => "baz" }, x => "y" } dd $hr; # { foo => { bar => "quz" } } unchanged my $shallow = { %{ $hr } }; $shallow->{foo}{bar} = 'baz'; $shallow->{x} = 'y'; dd $shallow; # { foo => { bar => "baz" }, x => "y" } dd $hr; # { foo => { bar => "baz" } } # original changed ^^^
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unable to make shallow copy of Moo hash ref attribute
by nysus (Parson) on Nov 13, 2018 at 14:41 UTC | |
by davido (Cardinal) on Nov 13, 2018 at 16:10 UTC | |
by davido (Cardinal) on Nov 14, 2018 at 16:10 UTC | |
by nysus (Parson) on Nov 17, 2018 at 09:37 UTC |