![]() |
[à intégrer au wiki] Les listes par l'exemple : aide-mémoire, astuces. - Version imprimable +- Communauté Eggdrop (https://forum.eggdrop.fr) +-- Forum : Eggdrop et scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=8) +--- Forum : Scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=4) +--- Sujet : [à intégrer au wiki] Les listes par l'exemple : aide-mémoire, astuces. (/showthread.php?tid=492) |
[à intégrer au wiki] Les listes par l'exemple : aide-mémoire, astuces. - MenzAgitat - 23/08/2009 Cet article ne prétend pas remplacer la documentation, mais plutôt la compléter en y apportant l'illustration par l'exemple. list list ?arg arg ...? set variable [list a b c] => a b c (définit une variable de type liste et contenant "a b c") _______________________________________
lindexlindex $list index index peut valoir "end" auquel cas le dernier élément de la liste est renvoyé. lindex {a b c d e f} 3 => d lindex {a b c d e f} end => f lindex {{a b c} {d e f} {g h i}} 1 1 => e lindex {{a b c} {d e f} {g h i}} 2 1 => h lindex {{a b c} {d e f} {g h i}} 2 0 => g _______________________________________
splitsplit $string ?splitChars? split "comp.unix.misc" . => comp unix misc split "ceci est un test" " " => ceci est un test split "ceci est un test" "e" => c {ci } {st un t} st _______________________________________
lappendlappend varName ?value value ...? lappend {a b c} 1 3 4 => a b c 1 3 4 _______________________________________
lreplacelreplace $list first last ?element element ...? lreplace {a b c} 0 0 @ => @ b c lreplace {a b c} 1 1 => a c lreplace {a b c d e f} 2 4 x y => a b x y f _______________________________________
ldelete n'existe pas mais il est possible d'en imiter la fonction :lreplace $list first last lreplace {1 2 3 4 5} 2 2 => 1 2 4 5 attention, ne pas faire : lreplace {1 2 3 4 5} 2 2 "" => 1 2 {} 4 5 _______________________________________
linsertlinsert $list index element1 ?element2 element3 ...? linsert {a b c} 0 d e f => d e f a b c linsert {a b c} 1 d e f => a d e f b c _______________________________________
llengthllength $list llength {a bcd e f} => 4 set testlist {a b c} llength "1 2 $testlist 3" => 6 éléments dans la liste substituée llength {1 2 $testlist 3} => 4 éléments dans la liste (dont $testlist n'a pas été substitué) _______________________________________
lrangelrange $list first last set testlist {a bcd e f} lrange $testlist 1 2 => bcd e lrange $testlist 1 end => bcd e f lrange $testlist 2 3 => e f _______________________________________
lsearchlsearch ?options? $list search_term voyez l'article du wiki pour connaître les options détaillées : http://www.eggdrop.fr/Lsearch Notez que l'option implicite est -glob si vous ne spécifiez ni -exact, ni -regexp. -glob -exact et -regexp sont des options exclusives, l'une exclut les autres. Une recherche -glob considèrera les * comme des jokers et les [ ] comme leurs équivalents regexp, [ab] signifiant a ou b. L'option -exact fera une recherche littérale dans la liste, considérant les * [ et ] comme des caractères normaux. lsearch {a b c d e} h => -1 lsearch {a b c d e} c => 2 _______________________________________
lsortlsort ?options? $list voyez l'article du wiki pour connaître les options détaillées : http://www.eggdrop.fr/Lsort _______________________________________
lreverselreverse $list lreverse {a b c d e} => e d c b a _______________________________________
lrepeatlrepeat number element1 ?element2 element3 ...? lrepeat 3 a => a a a lrepeat 3 [lrepeat 3 0] => {0 0 0} {0 0 0} {0 0 0} _______________________________________
lassignlassign $list varName1 ?varName2 ...? lassign [list a b c d e f g] variable1 variable2 set variable1 => a set variable2 => b _______________________________________
lrandomizelrandomize $list (mélange les éléments d'une liste) tcl
|