Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2015-11-26 16:44 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (703 votes), past polls