Tcl非常简单易学,让无涯教程开始创建第一个Tcl程序!
编写一个简单的Tcl程序。所有Tcl文件都将具有扩展名,即 .tcl。因此,将以下源代码放入test.tcl文件中。
#!/usr/bin/tclsh puts "Hello, World!"
假设Tcl环境设置正确;在切换到文件目录后运行程序,然后使用-
$tclsh test.tcl
将获得以下输出-
Hello, World!
现在看一下Tcl程序的基本结构,以便您轻松理解Tcl语言的基本构建块,在Tcl中,使用换行或分号来终止上一行代码。
#!/usr/bin/tclsh # 我在 Tcl 中的第一个程序 puts "Hello World!"
执行以上代码后,将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tcl-basic-syntax.html
来源:LearnFk无涯教程网
Hello World!
使用条件为" 0"的" if"写入多行或块注释。一个例子如下所示。
#!/usr/bin/tclsh if 0 { my first program in Tcl program Its very simple } puts "Hello World!"
执行以上代码后,将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tcl-basic-syntax.html
来源:LearnFk无涯教程网
Hello World!
内联注释使用;#,下面给出一个例子。
#!/usr/bin/tclsh puts "Hello World!" ;# 我在 Tcl 程序中的第一次打印
执行以上代码后,将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tcl-basic-syntax.html
来源:LearnFk无涯教程网
Hello World!
以下列表显示了Tcl中的一些保留字。这些保留字不得用作常量或变量或任何其他标识符名称。
after | append | array | auto_execok |
auto_import | auto_load | auto_load_index | auto_qualify |
binary | Bgerror | break | catch |
cd | Clock | close | concat |
continue | Dde | default | else |
elseif | Encoding | eof | error |
eval | Exec | exit | expr |
fblocked | Fconfigure | fcopy | file |
fileevent | Flush | for | foreach |
format | Gets | glob | global |
history | If | info | interp |
join | Lappend | lindex | linsert |
list | Llength | load | lrange |
lreplace | Lsearch | lsort | namespace |
open | Package | pid | pkg_mkIndex |
proc | Puts | pwd | read |
regexp | Regsub | rename | resource |
return | Scan | seek | set |
socket | Source | split | string |
subst | Switch | tclLog | tell |
time | Trace | unknow | unset |
update | Uplevel | upvar | variable |
vwait | while |
仅包含空格的行(可能带有注释)被称为空白行,而Tcl解释器会完全忽略它。
#!/usr/bin/tclsh puts "Hello World!"
" puts"和" Hello World!"之间必须至少有一个空格字符(通常是一个空格),以便解释器能够区分它们,另一方面,在以下语句中-
#!/usr/bin/tclsh puts [expr 3 + 2] ;# print sum of the 3 and 2
执行以上代码后,将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tcl-basic-syntax.html
来源:LearnFk无涯教程网
5
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)