Topic: A Challenge
I am after a sorting algorithm written in perl to perform the following task:
I have a variable number of files within a directory (anything from 0 to a couple of hundred) They are named very specifically in the following manner:
document1_rev-0
document2_rev-0
document2_rev-A
document2_rev-B
document3_rev-0
document4_rev-0
document4_rev-A
The documentx part of the file could be anything, the _rev-x part always starts at _rev-0 (zero) and each time the document is revised will change to A through to Z (it is be highly unlikley to ever reach Z). I want the algorithm to return a list showing only the latest revisions. ie the list above should appear as:
document1_rev-0
document2_rev-B
document3_rev-0
document4_rev-A
There are two ways this can be acheived, either keep a dynamic list updated as each file is read from disk in turn, or read all files into an array (or something similar) and then run the algorithm on the array to strip out old revisions. (Due to the nature/use of the files I do not want to use a database to perform the above).
I will pay the princely sum of £10 (In sterling or Amazon book tokens, should anyone not wish to disclose an address for it to be sent to) for the solution which I beleive is most efficient (this would be acheived by trial and error as I probably wouldn't be capable of determining it any other way. My decision would be final and not up for debate, Although I would expect if other postings are anything to go by a debate would rage on afterwards to a point where you will be counting clock cycles and how much further one particular electron had travelled around it silicon orbit)
On a serious note I look forward to receiving some feedback
Paul M