Clone::Util - Utilities related to cloning
This document describes version 0.03 of Clone::Util (from Perl distribution Clone-Util), released on 2016-03-10.
use Clone::Util qw(modclone sclone); my $row = {name=>'ujang', gender=>'m', nationality=>'id'}; my $table = [ $row, modclone { $_->{name} = 'budi' } $row, modclone { $_->{name} = 'asep' } $row, modclone { $_->{name} = 'rini'; $_->{gender} = 'f' } $row, ]; my $shallow_clone = sclone($data);
None of the functions are exported by default, but they are exportable.
This is just re-exported Function::Fallback::CoreOrPP's clone().
clone()
Clone $data and then run code. Code will be given the clone of data. For convenience, $_ will also be localized and set to the clone of data. So you can access the clone using $_ in addition to $_[0].
$data
$_
$_[0]
Shallow-clone $data, which must be an arrayref or a hashref. Shallow cloning means only copying the first level of data.
my $array = [0,1,2,[3]]; my $clone = sclone $array; # => [0,1,2,[3]], but [3] is still the same reference $clone->[3][0] = "three"; # $clone as well as $array become [0,1,2,["three"]] $clone->[0] = "zero"; # $clone becomes ["zero",1,...] but $array still [0,1,...]
You can perform shallow copying trivially yourself using:
my $cloned_array = [@$array]; my $cloned_hash = {%$hash};
Please visit the project's homepage at https://metacpan.org/release/Clone-Util.
Source repository is at https://github.com/perlancar/perl-Clone-Util.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Clone-Util
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Function::Fallback::CoreOrPP
perlancar <perlancar@cpan.org>
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Clone::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Clone::Util
CPAN shell
perl -MCPAN -e shell install Clone::Util
For more information on module installation, please visit the detailed CPAN module installation guide.