《TCL 教程英文版》 笔记 §16 添加删除LIST成员
时间:2008-08-26 来源:oychw
§16 添加删除LIST成员
concat ?arg1 arg2 ... argn?
lappend listName ?arg1 arg2 ... argn?
linsert listName index arg1 ?arg2 ... argn?
lreplace listName first last ?arg1 ... argn?
lset varName index newValue
实例:
# cat ch16
# !/bin/bash
# \
exec tclsh "$0" "$@"
set b [list a b {c d e} {f {g h}}]
puts "Treated as a list: $b\n"
set b [split "a b {c d e} {f {g h}}"]
puts "Transformed by split: $b\n"
set a [concat a b {c d e} {f {g h}}]
puts "Concated: $a\n"
lappend a {ij K lm} ;# Note: {ij K lm} is a single element
puts "After lappending: $a\n"
set b [linsert $a 3 "1 2 3"] ;# "1 2 3" is a single element
puts "After linsert at position 3: $b\n"
set b [lreplace $b 3 5 "AA" "BB"]
puts "After lreplacing 3 positions with 2 values at position 3: $b\n"
执行结果:
# ./ch16
Treated as a list: a b {c d e} {f {g h}}
Transformed by split: a b \{c d e\} \{f \{g h\}\}
Concated: a b c d e f {g h}
After lappending: a b c d e f {g h} {ij K lm}
After linsert at position 3: a b c {1 2 3} d e f {g h} {ij K lm}
After lreplacing 3 positions with 2 values at position 3: a b c AA BB f {g h} {ij K lm}