Scalar::Util::CloneScalar::Util::Clone can recursively copy datatypes using perl's builtin functions. | |
Download |
Scalar::Util::Clone Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- chocolateboy
- Publisher web site:
- http://search.cpan.org/~chocolate/Scalar-Util-Clone-0.04/lib/Scalar/Util/Clone.pm
Scalar::Util::Clone Tags
Scalar::Util::Clone Description
Scalar::Util::Clone can recursively copy datatypes using perl's builtin functions. Scalar::Util::Clone can recursively copy datatypes using perl's builtin functions.SYNOPSIS use Scalar::Util::Clone qw(clone); $a = Foo->new(); $b = { alpha => 'beta', gamma => 'vlissides' }; tie %c, 'Foo::Bar'; $d = clone($a); $e = clone($b); $f = clone(%c); # or my $node2 = { name => 'node2', children => , parent => weaken ($node1) # weaken() to avoid memory leak }; my $clone = clone($node2);This module exports a clone() function which unlocks the builtin functionality perl uses to clone a new interpreter and its values. As such, it is capable of cloning all perl datatypes, including weak references, hashes with shared keys, hashes with UTF8 keys, restricted hashes, tied variables, regex objects, and other curios lurking in Perl's intestines. Because the clone operation is performed at the lowest level, copying the datatype's internals rather than reconstructing it via the public API, the operation is fast and comprehensive, and produces values that exactly match their original (for instance, Data::Dumper dumps of hashes are always guaranteed to be the same as those of the original).For performance reasons, the following types are passed through transparently rather than being deep cloned: formats, code refs, typeglobs, IO handles, and stashes.clone returns a recursive copy of its argument, which can be an arbitrary (scalar) type including nested HASH, ARRAY and reference types, tied variables and objects.To duplicate non-scalar types (e.g. lists, ARRAYs and HASHes), pass them to clone by reference. e.g. my $copy = clone (@array); # or my %copy = %{ clone (%hash) };For a slower, but more flexible solution see Storable's dclone. Requirements: · Perl
Scalar::Util::Clone Related Software