Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 contemplating the Monastery: (7)
As of 2015-07-06 08:11 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (70 votes), past polls