如何将数组变成列表

时间:2018-07-17 15:49:01

标签: tcl

我正在尝试读取文件中的每一行,但是每次运行它都会出错:

set fr [open temp.txt r]
set a [read $fr]
set b [split $a '\n']
foreach i $b{
*code*
}

1 个答案:

答案 0 :(得分:-2)

此代码可以正常工作:

set fr [open input_file.txt r]
set a [read $fr]
close $fr
set b [split $a \n]
set fa [open temp.txt a]
foreach i $b {
   #Process items in list b
   puts $fa $i
}
close $fa
相关问题