in reply to Re^2: Unable to make shallow copy of Moo hash ref attribute
in thread Unable to make shallow copy of Moo hash ref attribute
Storable's dclone does what you are after, but may be heavier than you need, since it does a full freeze and thaw to and from memory. The advantage to dclone is it supports hooks to define serialization behavior. But often that's not needed. In cases where you don't need that flexibility, Clone provides a clone function that is somewhat lighter weight, and for a typical data structure will be faster.
In some cases rather than cloning a data structure you can get away with using local to override certain elements within the structure in a way where the changes unroll at end of dynamic scope. An example of this would be passing a structure in as an argument list, and needing to massage those args without having the changes propagate back to the caller. In that case, localizing a key or an element before fiddling with its value is a good approach that avoids a full clone.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Unable to make shallow copy of Moo hash ref attribute
by davido (Cardinal) on Nov 14, 2018 at 16:10 UTC | |
by nysus (Parson) on Nov 17, 2018 at 09:37 UTC |