|Come for the quick hacks, stay for the epiphanies.
Command line file sortingby swkronenfeld (Hermit)
|on Sep 05, 2007 at 17:10 UTC
swkronenfeld has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks, I just spent awhile formulating the following code. I'm quite sure that it can be improved on, and I'm interesting in knowing how. Here's the goal of the code:
I need to sort a list of directories, and select the second directory when sorted highest first. For example:
I want to sort them to
And I would select the second entry, dir-100-10.
Here's my code
A quick summary: it extracts the two numbers, sorts them, and prints out the 2nd entry in the sorted array. Note that I want to print the entire path, which will be an absolute path, unlike my contrived example here. There will always be two numbers separated by a dash, and they should always be sorted as I am doing so (left number, right side as a tie breaker). I bet there is a much simpler way to do what I want. I am ultimately looking for readability, not compactness (but if people turn this into a golf challenge, I would probably learn things too :).