#/usr/bin/perl -w use strict; use warnings; use Data::Dumper; #print `clear`; my @valuesNode1 = ( ['red1','GO:001'], ['red2','GO:002'], ['red3','GO:003'] ); my @valuesNode2 = ( ['blue1','GO:001'], ['blue2','GO:004'] ); my %nodeRelation1 = _get_base(); 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 = _get_base(); 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"; sub _get_base{ my %nodes = ( 'GO:001' => [0], 'GO:002' => [0], 'GO:003' => [0], 'GO:004' => [0] ); return %nodes; }