title: How do I sort a hash array by value in perl?
body: <p>I have a program that finds all the files in a directory and creates a hash array of their names and sizes.</p>
  
  <p>example</p>
  
  <pre><code>%files = ("file1" =&gt; 10, "file2" =&gt; 30, "file3" =&gt; 5);
  </code></pre>
  
  <p>I want to be able to sort the files by size descending and add the names/values to a new array.</p>
  
  <p>example</p>
  
  <pre><code>%filesSorted = ("file2" =&gt; 30, "file1" =&gt; 10, "file3" =&gt; 5);
  </code></pre>
  
  <p>I have found many ways to sort the array by value and then print the values but that's not what I want.</p>