# 任意长度排序,达到小或者小到大 proc num_sort {args} { parse_proc_arguments -args $args arguments echo "the length of the nums is [llength $arguments(nums)]" set input_nums [split$arguments(nums) ","] echo $input_nums if {[info exists arguments(-type)]} { if {[string equal arguments(-type) max2min]} { set result [lsort -decreasing -real $input_nums] } else { set result [lsort -increasing -real $input_nums] } } else { set result [lsort -decreasing -real $input_nums] } set w_file_handle [open"sort_result.txt" w] foreach i $result { puts$w_file_handle$i } close$w_file_handle set ouptut_nums [join$result","] echo $ouptut_nums }
define_proc_attributes num_sort \ -info"sort the nums, max to min or min to max" \ -command_group my_procs \ -define_args \ { {-type "max2min min2max, default is max2min""type"string optional} {nums "sort numbers""nums"string required} }
# 任意长度排序,达到小或者小到大 proc num_sort_removerepeat {args} { parse_proc_arguments -args $args arguments echo "the length of the nums is [llength $arguments(nums)]" set input_nums {} # 去除重复的数据 foreach number $arguments(nums) { if {[lsearch -exact $input_nums$number] >= 0} { set input_nums $input_nums } else { lappend input_nums $number } } echo $input_nums if {[info exists arguments(-type)]} { if {[string equal arguments(-type) max2min]} { set result [lsort -decreasing -real $input_nums] } else { set result [lsort -increasing -real $input_nums] } } else { set result [lsort -decreasing -real $input_nums] } set w_file_handle [open"sort_result.txt" w] foreach i $result { puts$w_file_handle$i } close$w_file_handle }
define_proc_attributes num_sort_removerepeat \ -info"sort the nums, max to min or min to max, the ouptut number just appear once" \ -command_group my_procs \ -define_args \ { {-type "max2min min2max, default is max2min""type"string optional} {nums "sort numbers""nums"list required} }