Tcl Workout

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Tcl Workout as PDF for free.

More details

  • Words: 681
  • Pages: 4
Simple Text output 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

Assigning variable values

The assignment command in Tcl is set. When set is called with two arguments, as in: set fruit Cauliflower

it places the second argument (Cauliflower) in the memory space referenced by the first argument (fruit). Set always returns the contents of the variable named in the first argument. Thus, when set is called with two arguments, it places the second argument in the memory space referenced by the first argument and then returns the second argument. In the above example, for instance, it would return "Cauliflower", without the quotes. Example: 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" output This is a string 1.24 ...............................

The value in Y is:

1.24

Evaluation & Substitutions 1: Grouping arguments with "" set Z Albany set Z_LABEL "The Capitol of New York is: " puts "$Z_LABEL $Z" puts "$Z_LABEL \$Z"

;# Prints the value of 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" puts "Lincoln is not on the $$a bill" puts "Hamilton is not on the \$a bill" puts "Ben Franklin is on the \$$a bill" puts puts puts puts on a

This This This But,

is not what you want is OK is not what you want this is OK

"\n................. examples of escape strings" "Tab\tTab\tTab" "This string prints out \non two lines" "This string comes out\ single line"

output The Capitol of New York is: Albany The Capitol of New York is: $Z

Ben Franklin is on the $100.00 bill Washington is not on the 100.00 bill Lincoln is not on the $100.00 bill Hamilton is not on the $a bill Ben Franklin is on the $100.00 bill

................. examples of escape strings Tab

;# ;# ;# ;#

Tab

Tab

This string prints out on two lines

This string comes out on a single line

Evaluation & Substitutions 1: Grouping arguments with {} grouping words with double quotes allows substitutions to occur within the double quotes. By contrast, grouping words within double braces disables substitution within the braces. Characters within braces are passed to a command exactly as written. The only "Backslash Sequence" that is processed within braces is the backslash at the end of a line. This is still a line continuation character.

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"

output The Capitol of New York is: Albany $Z_LABEL \$Z Ben Franklin is on the $100.00 bill Washington is not on the 100.00 bill Lincoln is not on the $100.00 bill Hamilton is not on the $a bill Ben Franklin is on the $100.00 bill ................. examples of escape strings Tab Tab Tab This string prints out on two lines This string comes out on a single line

Related Documents

Tcl Workout
June 2020 10
Workout
December 2019 18
Workout
November 2019 19
Workout
October 2019 19
Tcl Report
November 2019 21
Tcl-tutorial
October 2019 27