[Catalyst] Deep copying (was: A couple questions...)
Nate Wiger
nwiger at scea.com
Thu Sep 7 23:14:50 CEST 2006
Dylan Vanderhoof wrote:
>
> First question, is it possible to deep-copy a structure using TT?
Check Storable's dclone, or search CPAN for "clone". Or, use this for
simple structures:
# Anon copies of arrays/hashes
# Based on deep_copy example by merlyn
# http://www.stonehenge.com/merlyn/UnixReview/col30.html
sub deep_copy {
my $orig = shift;
return (ref $orig eq 'HASH')
? +{map { $_ => deep_copy($orig->{$_}) } keys %$orig}
: (ref $orig eq 'ARRAY') ? [map deep_copy($_), @$orig]
: $orig;
}
You're right, this issue can be super annoying.
-Nate
More information about the Catalyst
mailing list