How to? Array sort according to multiple keys

Dec 10, 2014
63
1
#1
I know tcc probably is not designed to be anywhere near Python or similar programing languages, but I tried to use arrays in a batch file nevertheless. My current problem is that I want to sort an array for a key, but the function I clumsily wrote with tcc takes ages to complete and I'm not able to code a multilayer quicksort (plugin authors, anyone?).

My actual application for this is to sort a long list of image metadata first according to the rating, and then according to the date/time (I converted the latter to age, so it's a simple numeric value).

Feature request: @ARRAYSORT[arrayvar, arraykey1, ...] to sort an array according to numeric value of the specified key(s)

If this won't happen, does anyone know of a smart method to sort something like this simple example array ...

array[0,0,0]=2
array[0,0,1]=100
array[0,0,2]=blablabla
array[0,1,0]=3
array[0,1,1]=100
array[0,1,2]=yadayada
array[0,2,0]=1
array[0,2,1]=300
array[0,2,2]=secondary
array[0,3,0]=1
array[0,3,1]=200
array[0,3,2]=primary

... in numeric order of the given array keys, in this case the first [n,n,0] and then the second [n,n,1]]? The result should be ...

%array[0,0,0]: 1
%array[0,0,1]: 200
%array[0,0,2]: primary
%array[0,1,0]: 1
%array[0,1,1]: 300
%array[0,1,2]: secondary
%array[0,2,0]: 2
%array[0,2,1]: 100
%array[0,2,2]: blablabla
%array[0,3,0]: 3
%array[0,3,1]: 100
%array[0,3,2]: yadayada

Thanks for any hints!
 
Last edited:
Dec 10, 2014
63
1
#4
Or echo the array with a loop while piping to TPIPE.
Right, good idea, that seems to work! I have to loop-write and -read the array though since there's no way to dump the whole array to a structured file and filearray only reads one-dimensional arrays :-\