Very efficient method of sorting hashes

Perl Add comments

One of the more interesting items Randal covered was the Schwartzian Transformation. Simply put, the Schwartzian Transformation is a very efficient way to sort hashes.
Here it is, in it’s entirety:

#!/usr/bin/perl

@sorted_files =
map { $_->[0] }
sort { $a->[1] < => $b->[1] }
map { [ $_, -s $_ ] }
< *>;

This example sorts a directory by file size but Randal assured us it can be easily modified to fit just about any situation.

Leave a Reply

You must be logged in to post a comment.

WebSite Powered by webHauser
Entries RSS Comments RSS Login