I have a TCL list which is output of sql query:
我有一个TCL列表,它是sql查询的输出:
CLI:
CLI:
% set res [$dbLab doSQL "SELECT DISTINCT p.platform, a.free FROM(
SELECT classification, SUM(CASE WHEN is_free = true THEN 1 ELSE 0 END
) AS free FROM device_availability_pts GROUP BY classification) a
INNER JOIN profile_platform p ON p.platform = a.classification
OR p.platform = a.classification ORDER BY free DESC;"]
Output:
输出:
{ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}
In this list 160 is the highest number , so i want this list index and its value inside the variable basically want to stor the highest of the list, i tried -stride and other functions of tcl 8.4, but 8.4 is not my version which is use,.
在这个列表中,160是最高的数字,所以我想要这个列表索引及其在变量里面的值主要想要在列表的最高位置,我尝试了-stride和tcl 8.4的其他功能,但是8.4不是我使用的版本。
so need some logic whicch will return me {ptsvpl-esxi 160}
in one variable
因此,需要一些逻辑的whicch将返回我{ptsvpl-esxi 160}在一个变量中。
2 个解决方案
#1
0
160 is the highest number ? If as for me the number 181 is the highest number. see attached my solution (There is certainly a more effective solution)
160是最高的数?如果对我来说,数字181是最高的数字。见附件我的解决方案(当然有更有效的解决方案)
set mlist [list {ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}]
set num {}
foreach el $mlist {
lappend num [lindex $el 1]
}
set num_max [join $num ,]
set num_max [expr max($num_max)]
set mysolution [lsearch -inline $mlist *$num_max]
#2
0
I don't have an 8.4 Tcl to test with, but according to the lsort man page this should work:
我没有8.4的Tcl来测试,但是根据lsort手册,这应该可以:
% set result [list {ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}]
% lsort -integer -index end -decreasing $result
{ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}
% lindex [lsort -integer -index end -decreasing $result] 0
ptsvpl-kvm 181
and then, if you want to assign those to individual variables:
然后,如果你想把它们分配给个体变量:
set max [lindex [lsort ...] 0]
foreach {platform free} $max break
puts $platform
puts $free
#1
0
160 is the highest number ? If as for me the number 181 is the highest number. see attached my solution (There is certainly a more effective solution)
160是最高的数?如果对我来说,数字181是最高的数字。见附件我的解决方案(当然有更有效的解决方案)
set mlist [list {ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}]
set num {}
foreach el $mlist {
lappend num [lindex $el 1]
}
set num_max [join $num ,]
set num_max [expr max($num_max)]
set mysolution [lsearch -inline $mlist *$num_max]
#2
0
I don't have an 8.4 Tcl to test with, but according to the lsort man page this should work:
我没有8.4的Tcl来测试,但是根据lsort手册,这应该可以:
% set result [list {ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}]
% lsort -integer -index end -decreasing $result
{ptsvpl-kvm 181} {ptsvpl-esxi 160} {pts24k 38} {pts22k 36} {pts32k 30}
% lindex [lsort -integer -index end -decreasing $result] 0
ptsvpl-kvm 181
and then, if you want to assign those to individual variables:
然后,如果你想把它们分配给个体变量:
set max [lindex [lsort ...] 0]
foreach {platform free} $max break
puts $platform
puts $free