Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #311 Deep copy an object

Create the new object y by cloning the all the contents of x, recursively.

classes
var
  x,y: TPersistent;
...
  y.assign(x);
...
let y = structuredClone(x);
use v5.7.3;
use Storable qw(dclone);
my $x = [ 1, 2, [ 'a' ], { x => [3,4] } ];

my $y = dclone $x;
import copy
y = copy.deepcopy(x)
y = Marshal.load(Marshal.dump(x))

New implementation...
< >
programming-idioms.org