title: How can I access the last Perl hash key without using a temporary array?
body: <p>How can I access the last element of keys in a hash without having to create a temporary array?</p>
  
  <p>I know that hashes are unordered. However, there are applications (like mine), in which my keys can be ordered using a simple <code>sort</code> call on the hash keys. Hope I've explained why I wanted this. The barney/elmo example is a bad choice, I admit, but it does have its applications.</p>
  
  <p>Consider the following:</p>
  
  <pre><code>my %hash = ( barney =&gt; 'dinosaur', elmo =&gt; 'monster' );
  my @array = sort keys %hash;
  print $array[$#{$hash}];
  #prints "elmo"
  </code></pre>
  
  <p>Any ideas on how to do this without calling on a temp (@array in this case)?</p>