Bonjour à tous,
J'ai 2 colonnes dans un tableau, $Compound et $StdInChIKey, contenant chacune le même nombres de valeurs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 # hash Characteristics[StdInChIKey] # hash de hash, key1 : $Compound and key2 : corresponding $StdInChIKey (we have to find only one k2 per k1) my %comp_tab; for my $i (1..$#tab){ my $Compound = $tab[$i][$Compound_index]; my $StdInChIKey = $tab[$i][$StdInChIKey_index]; next if (($Compound eq '') or ($StdInChIKey eq '')); $Compound = lc($Compound); $comp_tab{$Compound}{$StdInChIKey}++; } # check if we have only one K2 : $StdInChIKey per K1 : $Compound foreach my $Compound (keys %comp_tab){ my $StdInChIKey_num = (keys %{$comp_tab{$Compound}}); if ($StdInChIKey_num > 1){ print "ERROR : $rep\t$Compound\n"; } }
Je veux vérifier que pour chaque valeur de Compound, j'ai un StdInChIKey unique.
Je place donc Compound en première clé du hash, StdInChIKey en seconde clé dans un hash imbriqué.
Je vérifie ensuite, que pour chaque clé Compound, une seule entrée existe dans StdInChIKey.
Cela fonctionne très bien, mais je me demandais comment aurais-je pu faire plus simple.
N'hésiter pas à me poser des question si cela n'est pas clair.
D'avance merci pour votre aide.
Partager