數組我有一個數組路徑未排序排序在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)整理路徑 的索引或具有關鍵字列表(超羣,蘇珊)以獲得最終的文件
THX,瑪利亞
這是一個很好的解決方案,因爲它也將排序後的數字的','作爲附屬關鍵。但是它不會做的是將負數視爲正確,因爲它將'-'作爲分隔符,而不是減號。 (對於很多用途,這並不重要。) – 2014-09-26 07:44:20
@DonalFellows:我總是儘量避免考慮負面的事情。 – 2014-09-26 08:01:07