in reply to sort file list
Note that this code is very inefficient: it splits each string each time it has to make a comparison during sorting. But you should be alright as long as you only have hundreds of files in a listing. It also fails if the filenames have blanks in them.@arr=sort {split(/\s+/,$a)[-1] cmp split(/\s+/,$b)} @arr;
For a more serious routine, you could pick the line apart with a regular expression, change the array into a list of lists that contains the filename as one element and the original line as the other, sort based on the filename element, and in the final step throw the filename away, leaving the sorted list of lines. This is known as Schwartzian transform.
|
|---|