1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/usr/bin/tclsh # # Demonstrate Data Structures # using procedural wrappers proc UserAdd { Acct rName eMail phone } { global uData if {[info exists uData($Acct,rname)]} { return 1 } set uData($Acct,rname) $rName set uData($Acct,email) $eMail set uData($Acct,phone) $phone return 0 } puts stdout [UserAdd bpb\ Brian bilbrey@junk.com 555-1212] puts stdout [UserAdd tom\ Tom tom@junk.com 555-1212] puts stdout [UserAdd bpb\ Brian bilbrey@junk.com 555-1212] ****** ~/tcltk$ ./datas.tcl 0 0 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ~/tcltk$ tclsh % file exists hello3.tcl 1 % file executable testit 0 % file pathtype ./hello3.tcl relative % set dir1 home home % set dir2 brian brian % set dir3 tcltk tcltk % file join /$dir1 dir2 dir3 /home/dir2/dir3 % file delete testit~ % |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ~/tcltk$ tclsh % nslookup orbdesigns.com Server: 192.168.1.3 Address: 192.168.1.3#53 Name: orbdesigns.com Address: 64.81.69.163 % set d [date] Sun Mar 25 13:51:59 PST 2001 % puts stdout $d % set d [exec date] Sun Mar 25 13:52:19 PST 2001 % puts stdout $d Sun Mar 25 13:52:19 PST 2001 ****** % if [catch {open foo r} Chan] { puts stdout "Sorry, Dave...\n" } % gets $Chan One % gets $Chan Two % eof $Chan 0 % close $Chan % |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ~/tcltk$ cat input01.txt 1 + 2 4 + 5 7 - 9 ~/tcltk$ tclsh % set InFile [open input01.txt r] file3 % while {[gets $InFile Op] >= 0} { set Operation "expr $Op" set Result [eval $Operation] puts stdout "$Op = $Result\n" } 1 + 2 = 3 4 + 5 = 9 7 - 9 = -2 % |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |