下面的代码
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf[open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute namon the trace file
exec nam–a out.nam&
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run产生此错误
can't read "nffile5": no such variable
while executing
"set nf[open out.nam w]"
(file "Desktop/sample.tcl" line 4)这是我第一次在tcl工作。那么问题出在哪里呢?我只用下面的语句运行:> ns sample.tcl
发布于 2013-06-15 10:32:26
变量名后缺少一个空格:
set nf [open out.nam w]Tcl非常依赖于空格的正确使用。整个语言可以用12条规则来描述,列出了here。规则3:“命令中的单词用空格分隔(换行符除外,它是命令分隔符)。”
您的脚本中实际发生了什么:
文件句柄Tcl将命令分解为两个单词:执行命令set和括号中的参数
file5)。如果只提供了一个参数,set命令将返回给定名称的值您从未使用该名称为变量赋值,nffile5
https://stackoverflow.com/questions/17119446
复制相似问题