没有合适的资源?快使用搜索试试~ 我知道了~
首页《TCL 8.5 中文标准教程》
资源详情
资源评论
资源推荐
教程英文版 笔记
磁针石
联系方式: gmail and gtalk: xurongzhong#gmail.com qq:37391319 blog: oychw.cublog.cn
#承接软件自动化实施与培训等 gtalk: ouyangchongwu#gmail.com qq 37391319
#python qq group: 深圳自动化测试 python 群:113938272
#武冈深圳 qq 群:66250781
本书英文版地址:http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html
§1 介绍...........................................................................................................................................................................2
§2 运行 TCL..................................................................................................................................................................2
§3 简单文本的输出......................................................................................................................................................3
§4 变量赋值...................................................................................................................................................................3
§5 命令分析与置换 1:使用""分组参数....................................................................................................................4
§6 命令分析与置换 2:使用{}分组参数...................................................................................................................6
§7 命令分析与置换 3:使用[]分组参数.....................................................................................................................7
§8 命令结果-数学 101................................................................................................................................................8
§9 计算机与数值........................................................................................................................................................10
§10 数值比较 101-if.................................................................................................................................................10
§11 文本比较-switch...................................................................................................................................................11
§12 循环 101-while 循环..........................................................................................................................................13
§13 循环 102-For 和 incr..........................................................................................................................................14
§14 过程.......................................................................................................................................................................16
§15 过程的参数和返回值...........................................................................................................................................16
§16 变量作用域-global and upvar...........................................................................................................................17
§17 TCL 数据结构 101-列表....................................................................................................................................20
§18 添加删除 LIST 成员.............................................................................................................................................21
§19 更多的 LIST 命令-lsearch, lsort, lrange............................................................................................................22
§20 简单的模式匹配- "globbing"...............................................................................................................................24
§21 字符串子命令 - length index range.....................................................................................................................25
§22 字符串比较- compare match first last wordend..................................................................................................25
§23 修改字符串- tolower, toupper, trim, format........................................................................................................27
§24 正则表达式 101....................................................................................................................................................30
§25 更多正则表达式实例..........................................................................................................................................32
§26 正则表达式 102....................................................................................................................................................33
§27 关联数组...............................................................................................................................................................34
§28 更多的数组命令:迭代和在过程中使用..........................................................................................................38
§29 字典.......................................................................................................................................................................41
§30 文件访问 101........................................................................................................................................................44
§31 使用 file 和 glob 获取文件信息...........................................................................................................................46
§32 通过 EXEC 和 OPEN 执行其他程序..................................................................................................................51
§33 通过 info 检查变量或者命令是否存在..............................................................................................................53
§34 通过 info 查看解释器状态..................................................................................................................................55
§35 通过 info 查看过程..............................................................................................................................................56
§36 source....................................................................................................................................................................57
§37 使用包和命名空间创建可重用的库.................................................................................................................58
第 1 页 共 77 页
§38 eval.......................................................................................................................................................................61
§39 使用 format,list 进行命令构建...........................................................................................................................63
§40 使用 format, subst 进行替换而不计算................................................................................................................64
§41 改变工作目录......................................................................................................................................................65
§42 调试和错误 errorInfo errorCode catch error return.............................................................................................66
§43 trace.......................................................................................................................................................................69
§44 命令行参数和环境字符串..................................................................................................................................71
§45 取得脚本执行时间 time.......................................................................................................................................73
§46 I/O 通道:socket, fileevent, vwait........................................................................................................................73
§47 时间和日期:clock...............................................................................................................................................75
§48 时间和日期:clock...............................................................................................................................................77
§1 介绍
本书要求有程序设计基础。
相关资源:
新闻组:
中很多源码,讨论等。
irc.freenode.net 的 tcl 频道(好像用不了)
参考书籍:Tcl/Tk: A Developer's Guide,Practical Programming in Tcl and Tk
其他参考:
§2 运行 TCL
调用 tclsh 来执行,比如:tclsh hello.tcl。
单独输入 tclsh,会出现一个交互式 shell。tkcon.tcl 是一个更好的交互式 shell。另外还有一个 windows 的 shell:
wish,它会加载 Tk 扩展。Eclipse IDE 通过 DLTK
扩展,也提供了良好的 TCL 支持。更多支持 TCL 的 IDE 参见:
a list of IDEs with Tcl support。更多编辑器参见:catalogue of Tcl source code editors。
在解释器中可以这样获取帮助:info commands。
第 2 页 共 77 页
§3 简单文本的输出
TCL 使用 puts 输出。输出后同时开启一个新行。如果有多于一个单词,需要使用双引号或者大括号。双引号和
大括号的区别下节讲述。TCL 没有意义。
TCL 用回车或者分号分隔。使用#作为注释。如果#不在行首,之前必须有分号。
比如以下执行会报错:
puts "Hello, World - In quotes" ;# This is a comment after the command.
# This is a comment at beginning of a line
puts {Hello, World - In Braces}
puts {Bad comment syntax example} # *Error* - there is no semicolon!
puts "This is line 1"; puts "this is line 2"
puts "Hello, World; - With a semicolon inside the quotes"
# Words don't need to be quoted unless they contain white space:
puts HelloWorld
执行结果:
!"
#"
$""%"&&& &"%
'
%"(#"'')$*+*"",%
-.%/000"%12
在第 4 行的#号前面添加分号后,结果如下:
!"
#"
#"''
""3
""4
5""!"
HelloWorld
§4 变量赋值
TCL 中,一切都可以看做字符串,以加快速度,尽管实际上它们可能是 list, integer, double 等。TCL 的赋值语句
是 set。
第 3 页 共 77 页
set 变量名 【变量值】
如果变量名为 varName(index) , 则为数组。
如果变量值为空,则显示变量的值。
比如:
# tclsh
% set Y 1.24
1.24
% set Y
1.24
%
TCL 可以按名和值传递参数,和 C 类似。$表示取变量的值。
实例:
set X "This is a string"
set Y 1.24
puts $X
puts $Y
puts "..............................."
set label "The value in Y is: "
puts "$label $Y"
执行结果:
This is a string
1.24
...............................
67"341
§5 命令分析与置换 1:使用""分组参数
TCL 中,命令的计算分为 2 个阶段。第一阶段仅仅是替换,第 2 阶段计算命令的值。只替换一次。
比如在 "869 : "%%中,就是先把 varName 置换为”Hello World”,然后再输
出。
TCL 提供三种形式的置换:变量置换、命令置换和反斜杠置换。上面的例子就是变量置换。
[]中置换为命令的执行结果。
转义字符的置换:
String Output Hex Value
\a Audible Bell 0x07
\b Backspace 0x08
\f Form Feed (clear screen) 0x0c
第 4 页 共 77 页
\n New Line 0x0a
\r Carriage Return 0x0d
\t Tab 0x09
\v Vertical Tab 0x0b
\0dd Octal Value d is a digit from 0-7
\uHHHH H is a hex digit 0-9,A-F,a-f. This represents a 16-byte Unicode character.
\xHH.... Hex Value H is a hex digit 0-9,A-F,a-f. Note that the \x substitution "keeps going" as long as it has
hex digits, and only uses the last two, meaning that \xaa and \xaaaa are equal, and that \xaaAnd anyway will "eat"
the A of "And". Using the \u notation is probably a better idea.
位于行尾的”\” 用于续行。
注意 16 进制中的\xHH 为贪婪匹配,但是只使用最后 2 个值。使用\u 或许更好
实例:
set Z Albany
set Z_LABEL "The Capitol of New York is: "
puts "$Z_LABEL $Z" ;# Prints the value of Z
puts "$Z_LABEL \$Z" ;# Prints a literal $Z instead of the value of Z
puts "\nBen Franklin is on the \$100.00 bill"
set a 100.00
puts "Washington is not on the $a bill" ;# This is not what you want
puts "Lincoln is not on the $$a bill" ;# This is OK
puts "Hamilton is not on the \$a bill" ;# This is not what you want
puts "Ben Franklin is on the \$$a bill" ;# But, this is OK
puts "\n................. examples of escape strings"
puts "Tab\tTab\tTab"
puts "This string prints out \non two lines"
puts "This string comes out\
on a single line"
运行结果:
;97"<
;97"8=
#>"83????
""3????
"83????
"8
#>"83????
'";"""
"""
第 5 页 共 77 页
剩余63页未读,继续阅读
oychw
- 粉丝: 71
- 资源: 57
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2