note
grinder
<blockquote><i>But then I realized it'd probably be better to use Perl for the sorting, and got this shorter result</i></blockquote>
<p>Now that sounds like a challenge...</p>
<readmore>
<ol>
<li>The [return] is clearly superflous. Off with 7.</li>
<li>[0-9] can be replaced by \d, saving a character.</li>
<li>Hoist the exponentation into the hash values and use a bigger scaling factor (that may be written more concisely).</li>
<li>Replace $n and $u with $1 and $2 thus doing away with their initialisation.</li>
<li>Hang on, moving the exponentiation back into h() means that the hash declaration is shorter still.</li>
<li>If one considers that 'du -h|' adds to the overall count, then we can replace the diamond operator with a backtick of du -h. Overall this saves us the | of the pipe.</li>
<li>We can replace the fat commas with ordinary commas (and fortunately not receive warnings).</li>
<li>In fact, that regexp is way too verbose. <tt>/^(...)(.)/</tt> will work just as well, saving a couple of characters.</li>
<li>update: I forgot to add the last step, changing shift to pop (since we only read one arg).</li>
</ol>
<p>Which gives....</p>
<code>perl -e 'sub h{%h=(K,1,M,4,G,7);pop=~/^(...)(.)/&&$1**$h{$2}}print sort{h($b)<=>h($a)}`du -h`'</code>
<p>ok, ok, I promise I'll leave it alone now, there's just the idea of using an anonymous hash to shave off a couple more characters, and the parens can be dropped from h($a), (but not h($b) because of precedences):</p>
<code>perl -e 'sub h{pop=~/(...)(.)/&&$1**{K,1,M,4,G,7}->{$2}}print sort{h($b)<=>h$a}`du -h`'</code>
</readmore>
<p>... <strike>90</strike> 88 characters.</p>
<div class="pmsig"><div class="pmsig-29008">
<p align="right"><font size="-2">• another intruder with the mooring in the heart of the Perl</font></p>
</div></div>
746356
746356