Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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,

wufnik

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


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-09-16 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (47 votes), past polls