小编man*_*rma的帖子

为什么我不能在 TCL 中使用同一文件通道两次

我正在编写一个 TCL 程序,如下所示:

#!/usr/bin/tclsh
set fInp [open file1.txt r]
while {[gets $fInp line] >= 0} {
      statement 1
      statement 2
}

statement 3
statement 4

while {[gets $fInp line] >=0} {
      statement 5
      statement 6
}

close $fInp
Run Code Online (Sandbox Code Playgroud)

我原以为它能正常工作,但令我惊讶的是,第二个 while 循环根本没有被执行。我得出的结论是,我们无法使用相同的文件描述符(或通道)两次读取 TCL 中的文件

所以我关闭了 fInp 并使用 fInp2 再次打开该文件,它起作用了!

这种行为背后的原因是什么?还有其他方法吗?

谢谢

user-input tcl

0
推荐指数
1
解决办法
231
查看次数

在 TCL 中来回传递字典值

我正在尝试编写一个使用字典值来存储一些数据的脚本。然后,我将相同的字典值用于进一步处理的过程。它看起来像这样:

proc testProc {a} {
   some statements ...
   dict incr a key2 1
}

set dummy [dict create]
dict incr dummy key1 1
testProc $dummy 

puts "[dict get $dummy]"
Run Code Online (Sandbox Code Playgroud)

我期望得到的输出为:

键1 1 键2 1

相反,我得到了:

键1 1

如果我想要第一个输出,那么我应该怎么做。

谢谢

dictionary procedure tcl

0
推荐指数
1
解决办法
354
查看次数

标签 统计

tcl ×2

dictionary ×1

procedure ×1

user-input ×1