Clone#
Make a deep, independent copy of any Perl value - hashes, arrays, scalars, references, blessed objects, tied variables, and weak references.
clone walks a data structure recursively and returns a fresh copy. Shared references inside the input become shared references inside the copy (no accidental duplication), circular structures are reproduced without infinite recursion, weak references come out still weak, and tied variables keep their tie. Modifying the clone never touches the original.
For pure-Perl deep copies, Clone is typically faster than Storable::dclone on shallow to medium-depth structures (roughly three levels or fewer).
Synopsis#
use Clone qw(clone);
my $copy = clone($original); # function form
package Foo;
use parent 'Clone';
my $other = $obj->clone; # method form (inherited)
clone($data, $depth) copies only $depth levels and shares what lies below. This is a native implementation of Clone 0.50; its Clone.pm is used unchanged, and nothing is exported by default.
Differences from upstream#
None.
Functions#
Cloning#
clone#
Return a deep, independent copy of a Perl value.