Thread array kopieren: hash in array (3 answers)
Opened by Gast at 2006-12-08 11:22

renee
 2006-12-08 11:49
#72387 #72387
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Und ohne Modul:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

sub deep_clone($);

my @a=(0,1,2,3,4,5,{ich=> [1,2,3]});
print Dumper(\@a);
my @d=@{deep_clone(\@a)};
$d[6]{ich} = 'du';
$d[7]=8;
print Dumper(\@a,\@d);


sub deep_clone($){
my ($ref) = @_;

my $target;

unless(ref($ref)){
$target = $ref;
}
elsif(ref($ref) eq 'ARRAY'){
for my $idx(0..scalar(@$ref)-1){
$target->[$idx] = deep_clone($ref->[$idx]);
}
}
elsif(ref($ref) eq 'HASH'){
for my $key(keys %$ref){
$target->{$key} = deep_clone($ref->{$key});
}
}

return $target;
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread array kopieren: hash in array