March 2002 | Perl Hardware Store | 4 |
Schwartzian Transform
Sort list of items by some non-apparent feature
Example: Sort filenames by last-modified date
Obvious method is very wasteful:
sort { -M $b <=> -M $a } (readdir D);
Calls -M over and over on the same files
Idea:
Construct data structure with both names and dates
Sort by date
Throw away dates
Next | Copyright © 2002 M-J. Dominus |