在tcl中对数组进行排序

时间:2014-09-26 00:20:11

标签: arrays sorting arraylist tcl

我有一个未排序的数组路径

path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0
path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0

如果我使用lsort(数组名称路径),我会得到

path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0
path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0

但是我希望最终文件如下:

path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0
path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0

那怎么办?

a)排序路径索引 或者有关键字列表(maria,susan)来获取最终文件

Thx,Maria

2 个答案:

答案 0 :(得分:2)

尝试-dictionary的{​​{1}}选项。

lsort

文档:arraylsort

答案 1 :(得分:-1)

嗯...

path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0
path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0

不是未分类的。您可能希望按数字顺序查看索引。

path(Number,0)

然后数字就是订单!没有价值!是的,这是一个索引!!

路径始终按Number命令索引排序!依赖于输入顺序,显示顺序无论......

我从来没有听说过排序索引!