第二章 TCL 語言簡介 報告者:童耀民. 變數 (variable) 和變數替換 (variable substituion) 2-1-1 set foo "john" puts "my name is $foo“ 2-1-2 set month 2 set day 3 set year 97 set.

Slides:



Advertisements
Similar presentations
1/12 Steven Leung Very Basic Perl Tricks A Few Ground Rules File I/O and Formatting Operators, Flow Control Statements Regular Expression Subroutines Hash.
Advertisements

CIS 240 Introduction to UNIX Instructor: Sue Sampson.
LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast.
Adapted from John Zelle’s Book Slides
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Programming Using Tcl/Tk These slides are based upon u several Tcl/Tk text books u material byDr. Ernest J. Friedman-Hill.
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
Tcl/TK Tutorial Fan Yang Kristy Hollingshead
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002.
Innovation Intelligence ® 1 Chapter 1: Introduction to TCL.
REVIEW Surie SMKDPM2009. Q1 : Write a while loop that output the numbers 2, 4, 6, 8,..., 20. Answer : i=2; While(i
Tcl and Otcl Tutorial Part II Internet Computing KUT Youn-Hee Han.
1 Shell Scripting (C shell) SungHo Maeung 10/27/2000 Tutorial section Computer Science Lab.
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Dongsoo S. Kim  Tcl: Tool Command Language Interpreted programming (scripting) language Build on-the-fly commands and procedures Embeddable.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
Introduction to Programming with Tcl. Introduction Using two languages  C++ for “ data ”  Otcl for control Tcl has been widely used as a scripting language.
Scripting.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to Python Lesson 2a Print and Types.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
TCL/TK Tool Command Language/Tool Kit. What is TCL? u Tool Command Language u An interpreted programming language  Created by John Ousterhout.John Ousterhout.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
TCL Training Joshi Sravan Kumar K 21-Nov-2011.
FIND THE VOLUME: 5 in 8 in 4 in.
CS Computer Science IA: Procedural Programming
Chapter 10 Arrays.
Decisions Chapter 4.
Basic operators - strings
JavaScript Syntax and Semantics
Introduction to NS Srinath Perur.
Programming Using Tcl Maxwell Created By: Quan Nguyen Created Date: 12/12/2016 TCL Training1.
Conditionals, Loops, and Other Kinds of Statements
Topic 11 Scanner object, conditional execution
TCL/TK Tool Command Language/Tool Kit.
Chapter 10 Arrays.
Chapter 6 Arrays.
Variables, Loops, Decision Statements, etc
Review for Final Exam.
Context.
برنامه نویسی پیشرفته اصول جاوا.
Logical Operations In Matlab.
Basics.
Arrays Topics Definition of a Data Structure Definition of an Array
Review for Final Exam.
Sight Words.
1D Arrays and Lots of Brackets
1D Arrays and Lots of Brackets
CS1110 Today: collections.
Fundamental Programming
Trick Words 1st grade.
Last year Mary was twice as old as John.
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
1st GRADE SIGHT WORDS.
1D Arrays and Lots of Brackets
Write the word..
Arrays Topics Definition of a Data Structure Definition of an Array
Arrays Introduction to Arrays Reading for this Lecture:
1D Arrays and Lots of Brackets
Presentation transcript:

第二章 TCL 語言簡介 報告者:童耀民

變數 (variable) 和變數替換 (variable substituion) set foo "john" puts "my name is $foo“ set month 2 set day 3 set year 97 set date "$month:$day:$year" puts $date set foo "puts hi" eval $foo

表示式 (expressions) set value [expr 0==1] puts $value set value [expr 2>=1] puts $value set value [expr 2+3] puts $value

指令替換 (command substitution) puts "I am [expr 10 * 2] years old, amd my I.Q. is [expr ] " set my_height 6.0 puts "If I was 2 inches taller, I would be [expr $my_height+(2.0/12.0)] feet tall"

流程控制 (control flow) set my_planet "earth" if {$my_planet == "earth"} { puts "I feel right at home." } elseif {$my_planet == "venus"} { puts "This is not my home." } else { puts "I am neifher from Earth, nor from Venus." } set temp 95 if {$temp <80} { puts "It's a little chilly." } else { puts "Warm enough for me." } set num_legs 4 switch $num_legs { 2 {puts "It could be a human."} 4 {puts "It could bs a cow."} 6 {puts "It could bs an ant."} 8 {puts "It could bs a spider."} default {puts "It could be anything."} }

流程控制 (control flow) for {set i 0} {$i < 5} {incr i 1} { puts "In the for loop, and i ==$i" } set i 0 while {$i < 5} { puts "In the while loop, and i == $i" incr i 1 } foreach vowel {a e i o u} { puts "$vowel is a vowel" }

程序 (procedures) proc sum_proc {a b} { return [expr $a + $b] } proc magnitude {num} { if {$num > 0} { return $num } set num [expr $num * (-1)] return $num } set num1 12 set num2 14 set sum [sum_proc $num1 $num2] puts "The sum is $sum" puts "The magnitude of 3 is [magnitude 3]" puts "The magnitude of -2 is [magnitude -2]“ proc dumb_proc {} { set myvar 4 puts "The value of the ;oca; variable is $myvar" global myglobalvar puts "The value of the global variable is $myglobalvar" } set myglobalvar 79 dumb_proc

陣列 (arrays) set myarray(0) "0000" set myarray(1) "1111" set myarray(2) "2222" for {set i 0} {$i < 3} {incr i 1} { puts $myarray($i) } set person_info(name) "Fred Smith" set person_info(age) "25" set person_info(occupation) "Plumber" foreach thing {name age occupation} { puts "$thing == $person_info($thing)" } set person_info(name) "Fred Smith" set person_info(age) "25" set person_info(occupation) "Plumber" foreach thing [array names person_info] { puts "$thing == $person_info($thing)" }

字串 (strings) set str "this is a string" puts "The string is:$str" puts "The length of the string is:[string length $str]" puts "The character at index 3 is : [string index $str 3]" puts "The characters from index 4 through 8 are: [string range $str 4 8]" puts "The index of the first occurrence of letter \"i\" is: [string first i $str]"

輸出 (output) set f [open "/tmp/myfile" "w"] puts $f "We live in Texas. It's allready 110 degrees out here." puts $f "456" close $f

內容出處  書名:計算機網路實驗 (NS2 模擬工具實作 )  作者:柯志亨,程榮祥 ,謝錫堃,黃文祥等  出版社:學貫出版社  出版日: 2007/10/26  ISBN :  語言:中文繁體