in reply to Copying an array or hash

Here's the deep copy sub that I use in some of my objects:
sub deep_copy { my $self = shift; my $this = shift; unless (ref $this) { $this; } elsif (ref $this eq 'ARRAY') { [map $self->deep_copy($_), @$this]; } elsif (ref $this eq 'HASH') { +{map{$_ => $self->deep_copy($this->{$_})} keys %$this +}; } }
Here's the sub that calls it:
sub copy { my $self = shift; return $self->deep_copy($self); }
of course, this works because I assume my object will only either have hashrefs, arrayrefs or scalars.