title: In Perl, how can I sort hash keys using a custom ordering?
body: <p>I am trying to do work on a hash of files and the work has to be done in a specific order. Most would say the list can be ordered like so:</p>
  
  <pre><code>for my $k (sort keys %my_hash)
  {
      print "$k=&gt;$my_hash{$k}, ";
  }
  </code></pre>
  
  <p>However, I need nonalphabetical order, in fact the keys start with a word then <code>_</code> and they go <code>G</code> to <code>digits</code> to <code>L</code> to any of <code>M,P,R,T or D</code> (eg. <code>word_G.txt</code>,<code>word_2.txt</code>,...,<code>word_P.txt</code>). Is there any way to sort by custom order?</p>