title: Perl: Access a hashref sorted by value
body: <p>I'm writing a script that'll read through my ftpd logs and generate a hash as follows:</p>
  
  <pre><code>$stats = \{
              'user1' =&gt; {
                          'files' =&gt; 281,
                          'size' =&gt; '3724251021'
                        },
              'user2' =&gt; {
                        'files' =&gt; 555,
                        'size' =&gt; '7385856997'
                      },
              'user3' =&gt; {
                            'files' =&gt; 235,
                            'size' =&gt; '3716904486'
                          },
              'user4' =&gt; {
                         'files' =&gt; 578,
                         'size' =&gt; '8536026929'
                       }
            };
  </code></pre>
  
  <p>How do I access this hash with the keys sorted by size?</p>
  
  <p>I tried this but I get an error saying not a hashref</p>
  
  <pre><code>foreach my $user (sort { $$stats-&gt;{$a}-&gt;{size} cmp $$stats-&gt;{$b}-&gt;{size} } keys %$stats) {
  
  blahblahblah...
  }
  </code></pre>