LOL
ok, matey, sorry. I should have been more careful not to write gibberish! ;-)
I hope the array allocation is obvious.
The "my @sorted" line is the one that does all the work, obviously, so the explanation will be purely about that.
The "@files" on the end is the array that we're sorting and the "sort" on the front is the sort function so now we're left with the meat between the first opening curly brace and the last closing curly brace.
Since it's a block, we can scope our variables with "my" to avoid them trading on the toes of anything else.
There are two regexs to setup $s, $x, $t and $y. The sort function provides two values to compare (too see if they need swapping) $a and $b). They are the focus of the regex processing.
Each reges is identical, one works on $a and the other, $b.
The "$a =~" binds the reges to "$a" (in the first case and, as you can see the same applies to "$b" in the second).
The regex is overcomplicated by the fact that this is for windoze and windoze uses a backslash as the path separator. All backslashes in regexs need to be escaped with another backslash and that's why there's always two at a time.
So now then, we are matching a backslash "\\" followed by one or more non backslash characters "[^\\]+" which we capture using parentheses "()" so that it will be assigend to the first scoped variable (in this case $s).
Next we match another backslash "\\" along with one or more non digit characters. When this is matched, it's all just thrown away because we don't need it. Finally we match one or more digits and capture that (to assign to $x), right up to the end (forced by "$" which matches the end of string). The "$" ensures that we match this sequence where we expect it (at the end of the string) and not earlier in a very long path.
Phew!
By this time, we have the filename number in $x and the directory name (folder name for windoze guys) in $s.
Once this is repeated for the other path ($b) we can compare file numbers and directory names.
The last step then is relatively simple. If we are in the same directory ($s eq $t) then we can simply return whether to sort based on file number only. We do this with "return $x <=> $y" which does a numeric test and flags which is the greater.
If the directories are different, we compare those with a text comparison (cmp) and again, return a flag for which is greater.
So ends the lesson for how my gibberish works! ;-)
I hope that explains it a little. It certainly killed my fingers typing all that explanation!
Trojan.