title: Sort by value hash of hash of hashes Perl
body: <p>I have a hash structure similar to the following:</p>
  
  <pre><code>KeyA =&gt; {
           Key1 =&gt; {
                     Key4 =&gt; 4
                     Key5 =&gt; 9
                     Key6 =&gt; 10
                   }
           Key2 =&gt; {
                     Key7 =&gt; 5
                     Key8 =&gt; 9
                   }
          }
  KeyB =&gt; {
           Key3 =&gt; {
                     Key9 =&gt; 6
                     Key10 =&gt; 3
                   }
          }
  </code></pre>
  
  <p>I need to print out the traversal path through the hash structure and the value at the end of the traversal, such that this is ordered by value.
  For example, for the above hash structure I need to print:</p>
  
  <pre><code>KeyB Key3 Key10 3
  KeyA Key1 Key4  4
  KeyA Key2 Key7  5
  KeyB Key3 Key9  6
  KeyA Key2 Key8  9
  KeyA Key1 Key5  9
  KeyA Key1 Key6  10
  </code></pre>
  
  <p>Currently, to solve this I am traversing the hash structure using nested foreach loops, and creating a flattened hash by inserting an element with key equal to the traversal path (e.g. "KeyA Key3 Key10") and value equal to the value at the end of the traversal path (e.g. 3), then doing another foreach loop which sorts the flattened hash by value.</p>
  
  <p>Is there a more efficient way to do this?</p>