my %A = (
a => {
aa => [ 1, 2, 3, 4, 5 ],
bb => { aaa => 1, bbb => 2 },
},
);
my %B = %A.deepmap(-> $c is copy {$c});
dd %A;
dd %B;
%B<a><aa>[2] = 735;
dd %A;
dd %B;
Use .cloneand deepmapto request a copy / deep copy of the data structure. But do not bet on it. Any object can determine it by the method cloneand do whatever it wants with it. If you must mutate and therefore must clone, make sure you test your program with large data sets. Bad algorithms can make a program almost useless in production.
user5854207
source
share