title: Iterate through a hash and an array in Perl
body: <p>I have an array and a hash:</p>
  
  <pre><code>@arraycodons = "AATG", "AAAA", "TTGC"... etc.
  %hashdictionary = ("AATG" =&gt; "A", "AAAA" =&gt; "B"... etc.)
  </code></pre>
  
  <p>I need to translate each element of the array for the corresponding value in hashdictionary. However, I obtain a wrong translation.....</p>
  
  <p>To see the problem, I have printed $codon (each element of the array), but each codon is repeated several times..... and It shouldn't.</p>
  
  <pre><code>sub translation() {
      foreach $codon (@arraycodons) {
          foreach $k (keys %hashdictionary) {
              if ($codon == $k) {
                  $v = $hashdictionary{$k};
                  print $codon;
              }
          }
      }
  }
  </code></pre>
  
  <p>I don't know if I've explained my problem well enough, but I can't go on with my code if this doesn't work...</p>
  
  <p>Many thanks in advance.</p>