====== Sorting an array ====== This page is part of the Tcl/Tk page of the Airplug documentation.\\ [[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] / [[en:doc:summary|Back to Airplug documentation page]]. --- Le principe est de trier les indices du tableaux. Pour cela, utiliser la fonction lsort avec l'option -command sur les indices du tableau : array set tab {} # On définit la fonction de tri proc tri { a b } { global tab if { $tab($a) < $tab($b) } {return -1} if { $tab($a) > $tab($b) } {return 1} return 0 } # On récupère la liste des indices set indices [array names tab] # On trie les indices grâce à la fonction de tri set indices [lsort -command tri $indices] # On parcourt les indices triés foreach i $indices { set element $tab($i) ... }
---- This page is part of the Tcl/Tk page of the Airplug documentation.\\ [[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] / [[en:doc:summary|Back to Airplug documentation page]].