首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置nf时出现tcl错误[open out.nam w]

设置nf时出现tcl错误[open out.nam w]
EN

Stack Overflow用户
提问于 2013-06-15 09:41:28
回答 1查看 2.7K关注 0票数 0

下面的代码

代码语言:javascript
复制
#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

产生此错误

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-15 10:32:26

变量名后缺少一个空格:

代码语言:javascript
复制
set nf [open out.nam w]

Tcl非常依赖于空格的正确使用。整个语言可以用12条规则来描述,列出了here。规则3:“命令中的单词用空格分隔(换行符除外,它是命令分隔符)。”

您的脚本中实际发生了什么:

文件句柄Tcl将命令分解为两个单词:执行命令set和括号中的参数

  • 命令,并替换结果(返回的文件句柄名称为file5)。如果只提供了一个参数,
  • set命令将返回给定名称的值您从未使用该名称为变量赋值,nffile5
    • 将返回一个值

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17119446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档