Justin Mason wrote:

Michael Parker writes:


On Wed, Dec 15, 2004 at 11:05:31AM -0800, Justin Mason wrote:


in the short term though -- I don't think there's any need to use
a serialization format at all; just copy the data a la

%{$copy->{blah}} = %{$self->{blah}};


Hmmm....does this provide a deep enough copy?



well, we know how deep it needs to be, so yes it can ;)

- --j.

So long as there aren't any recursive data pointers (I don't think there are any... I could be wrong) this should work:

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


Daryl



Reply via email to