On Jun 13, 2009, at 1:54 AM, Chas. Owens wrote:


If you need to make a deep copy a data structure you should use the
dclone function from the Storable[1] module:

use Storable qw/dclone/;

Thanks!

I did find something Randal Schwartz had posted somewhere that did the trick for me -

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 $_?" }
}

- but I assume that dclone is the preferred way to go :-)

Chap

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to