Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Deep Copying of Nested Data-Structures

by wufnik (Friar)
on Sep 01, 2003 at 12:12 UTC ( [id://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 --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-24 11:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found