Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Deep Copying of Nested Data-Structures

by wufnik (Friar)
on Sep 01, 2003 at 12:12 UTC ( #288119=note: print w/ replies, xml ) Need Help??

in reply to Deep Copying of Nested Data-Structures

personally, i like the following, nicked shamelessly from the font of merlyn. nice esp. if you do not want the overhead of another module.

sub deepcopy{ my $this = shift; if (not ref $this){ $this; } elsif (ref $this eq "ARRAY") { [map deepcopy($_), @$this]; } elsif (ref $this eq "HASH"){ scalar { map { $_ => deepcopy($this->{$_}) } keys %$this }; } else { die "what type is $_?"} }
hope that helps,


-- in the world of the mules there are no rules --

Comment on Re: Deep Copying of Nested Data-Structures
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://288119]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-10-24 12:45 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (131 votes), past polls