title: Sorting hash keys by Alphanumeric sort
body: <p>I have just read the post <em><a href="https://stackoverflow.com/questions/19544253">Sorting alphanumeric hash keys in Perl?</a></em>. But I am starting with Perl, and I don't understand it very clearly.</p>
  
  <p>So I have a hash like this one:</p>
  
  <pre><code>  %hash = (
          "chr1" =&gt; 1,
          "chr2" =&gt; 3,
          "chr19" =&gt; 14,
          "chr22" =&gt; 1,
          "X" =&gt; 2,
      )
  </code></pre>
  
  <p>I'm trying to obtain output like this:</p>
  
  <pre><code>chr1
  chr2
  chr19
  chr22
  </code></pre>
  
  <p>But I'm obtaining output like this:</p>
  
  <pre><code>chr1
  chr19
  chr2
  chr22
  </code></pre>
  
  <p>I have written this code, but it is creating the above wrong output:</p>
  
  <pre><code>foreach my $chr (sort {$a cmp $b} keys(%hash)) {
      my $total= $hash{$chr};
      my $differentpercent= ($differenthash{$chr} / $total)*100;
      my $round=(int($differentpercent*1000))/1000;
      print "$chr\t$hash{$chr}\t$differenthash{$chr}\t$round\n";
  }
  </code></pre>
  
  <p>It prints:</p>
  
  <pre><code>chr1    342421    7449    2.175
  chr10    227648    5327    2.34
  chr11    220415    4468    2.027
  chr12    213263    4578    2.146
  chr13    172379    3518    2.04
  chr14    143534    2883    2.008
  chr15    126441    2588    2.046
  chr16    138239    3596    2.601
  chr17    122137    3232    2.646
  chr18    130275    3252    2.496
  chr19    99876    2836    2.839
  chr2    366815    8123    2.214
  </code></pre>
  
  <p>How can I fix this?</p>