Thread new_hash = old_hash ....desaster: Hash bekommt Elemente übertragen,... (3 answers)
Opened by xeroxed_yeti at 2007-07-19 12:30

renee
 2007-07-19 12:57
#78648 #78648
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hat damit zu tun, dass Du Referenzen "kopierst".

Es ist ganz schön zu sehen mit:
Code (perl): (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#/usr/bin/perl -w

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

#print  `clear`;
my %nodes = (
    'GO:001' => [0],
    'GO:002' => [0],
    'GO:003' => [0],
    'GO:004' => [0]
    );
    
my @valuesNode1 = (
    ['red1','GO:001'],
    ['red2','GO:002'],
    ['red3','GO:003']
    );
my @valuesNode2 = (
    ['blue1','GO:001'],
    ['blue2','GO:004']
    );


my %nodeRelation1 = %nodes;
foreach my $ref (@valuesNode1) {
    my $value = $ref->[0];
    my $id = $ref->[1];
    if (exists $nodeRelation1{$id}) {    
        ${$nodeRelation1{$id}}[0]++;
        push (@{$nodeRelation1{$id}}, $value);
    }        
}
print "\n";
foreach my $key (sort keys %nodeRelation1) {
    print "nodeRelation1: $key\t",$nodeRelation1{$key},"\n";#@tmp\n";        
}
print "\n";
  
my %nodeRelation2 = %nodes;  
foreach my $ref (@valuesNode2) {
    my $value = $ref->[0];
    my $id = $ref->[1];
    if (exists $nodeRelation2{$id}) {
        ${$nodeRelation2{$id}}[0]++;
        push (@{$nodeRelation2{$id}}, $value);
    }        
}
print "\n";
foreach my $key (sort keys %nodeRelation2) {
    print "nodeRelation2: $key\t",$nodeRelation2{$key},"\n";#@tmp\n";
}
print "\n";


Ausgabe:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
nodeRelation1: GO:001   ARRAY(0x234f18)
nodeRelation1: GO:002 ARRAY(0x234ffc)
nodeRelation1: GO:003 ARRAY(0x234e34)
nodeRelation1: GO:004 ARRAY(0x18bb230)


nodeRelation2: GO:001 ARRAY(0x234f18)
nodeRelation2: GO:002 ARRAY(0x234ffc)
nodeRelation2: GO:003 ARRAY(0x234e34)
nodeRelation2: GO:004 ARRAY(0x18bb230)


Wie man sieht, sidn die "Adressen" der Arrays für beide Hashes gleich...\n\n

<!--EDIT|renee|1184835596-->
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 new_hash = old_hash ....desaster: Hash bekommt Elemente übertragen,...