[ACCEPTED]-What's the best way to deep copy a hash of hashes in Perl?-deep-copy
Accepted answer
use Storable qw(dclone);
$group2 = dclone(\%group);
0
From the Storable::dclone documentation 2 I found Clone:
my $copy = clone (\@array);
# or
my %copy = %{ clone (\%hash) };
Don't need flexibility, and claims 1 to be faster than Storable::dclone.
Deep data structure 101:
- Use Storable's
dclone
to make a deep copy of a structure, andfreeze
andthaw
to serialize/deserialize them for storage (say in a database, or an http cookie (but you should encrypt anything you send to the user to make it harder to tamper with). - Use Data::Compare (or Test::Deep or Test::Differences inside a unit test) to compare two deep data structures.
- Use Data::Dumper or Data::Dump in debugging to see what your objects look like. But don't use that as a licence to tamper with another object's internals; use the API. :)
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.