This message is one of several periodic postings to DevShed's Perl forum intended to make it easier for Perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with every Standard Distribution of Perl.

How do I print out or copy a recursive data structure?

The Data:umper module on CPAN (or the 5.005 release of Perl) is great
for printing out data structures. The Storable module, found on CPAN,
provides a function called `dclone' that recursively copies its argument.

use Storable qw(dclone);
$r2 = dclone($r1);

Where $r1 can be a reference to any kind of data structure you'd like. It
will be deeply copied. Because `dclone' takes and returns references,
you'd have to add extra punctuation if you had a hash of arrays that you
wanted to copy.

%newhash = %{ dclone(%oldhash) };

Documents such as this have been called "Answers to Frequently Asked Questions" or FAQ for short. They serve to reduce the volume of redundant traffic on this bulletin board by providing quality answers to questions that keep comming up. If you find errors or other problems with these postings please send corrections or comments to the posting email address.

Written by Anonym0us, inspired by the original PerlFAQ Server.