admin管理员组文章数量:1332383
I have this list
set csv [list]
lappend csv [list \
a \
b \
c \
[expr {[cfg::get enable_all_columns]
? {
d
}
: {}
}] \
e \
f \
g]
I need to add element d
only if enable_all_columns
is 1
. The problem is that with this approach if it is 0
, it returns something empty which creates a new column in csv
raport.
That lappend
to output this list {a b c d e f g}
I tried to break the lappend
to put the condition and then add the last ones, but this results in this {a b c} d e f g
I also tried linsert
but it did the same
set csv [list]
lappend csv [list \
a \
b]
set csv [linsert $csv 1 x]
puts "$csv"
I have this list
set csv [list]
lappend csv [list \
a \
b \
c \
[expr {[cfg::get enable_all_columns]
? {
d
}
: {}
}] \
e \
f \
g]
I need to add element d
only if enable_all_columns
is 1
. The problem is that with this approach if it is 0
, it returns something empty which creates a new column in csv
raport.
That lappend
to output this list {a b c d e f g}
I tried to break the lappend
to put the condition and then add the last ones, but this results in this {a b c} d e f g
I also tried linsert
but it did the same
set csv [list]
lappend csv [list \
a \
b]
set csv [linsert $csv 1 x]
puts "$csv"
Share
edited Nov 22, 2024 at 9:18
Schelte Bron
4,8131 gold badge8 silver badges13 bronze badges
asked Nov 22, 2024 at 5:10
RazvanRazvan
11 bronze badge
2 Answers
Reset to default 0I would do it this way:
set csv {a b c e f g}
if {[cfg::get enable_all_columns]} {
set csv [linsert $csv 3 d]
}
Expansion allows you to make something that disappears when empty.
set csv [list]
lappend csv [list a b c {*}[if {[cfg::get enable_all_columns]} {
list d
}] e f g]
本文标签: insertTCLA condition for an item while appending items to a listStack Overflow
版权声明:本文标题:insert - TCL - A condition for an item while appending items to a list - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742296301a2448796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论