> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/perl6-rosettacode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/perl6-rosettacode/programming_tasks/d/deepcopy.md).

# Deepcopy

Raku doesn't currently provide a proper mechanism for deep copies, but depending on your requirements you could use one of these work-arounds:

**1) Use `.deepmap(*.clone)`:**

`.deepmap` constructs a copy of the data structure, and `.clone` makes a shallow copy of each leaf node. Limitations:

```perl
my %x = foo => 0, bar => [0, 1];
my %y = %x.deepmap(*.clone);

%x<bar>[1]++;
say %x;
say %y;
```

#### Output:

```
{bar => [0 2], foo => 0}
{bar => [0 1], foo => 0}
```

**2) Use `.raku.EVAL`:**

`.raku` serializes the data structure to Raku code, and `.EVAL` deserializes it. Limitations:

```perl
my %x = foo => 0, bar => [0, 1];
my %y = %x.raku.EVAL;

%x<bar>[1]++;
say %x;
say %y;
```

#### Output:

```
{bar => [0 2], foo => 0}
{bar => [0 1], foo => 0}
```
