Created
June 17, 2015 15:25
-
-
Save xuchunyang/25c2b1198706af90903d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tclsh | |
# hello-tcl.tcl | |
# Make some variables for testing | |
set name "Chunyang Xu" | |
set age 22 | |
set mail [format "%s@%s" chunyang macports.org] | |
set blog http://xuchunyang.me | |
# 1. Firstly, introduce me | |
puts "Hi, My name is $name, I'm $age \([expr $age+1]?\) years old. | |
You can contact me via $mail. | |
I also have a blog $blog." | |
puts [format "%s\n%s\n%s\n%s" $name $age $mail $blog] | |
join [list $name $age $mail $blog] "\n" | |
join [split [join [list $name $age $mail $blog] "\n"] "\n"] "\t" | |
# 1. And, play with some string commands | |
## length | |
puts "There are [string length $name] characters in my name \"$name\". " | |
## string cat ?string1? ?string2...? | |
puts [string cat "My name is " $name ", " "I'm " $age " years old."] | |
## string compare ?-nocase? ?-length length? string1 string2 | |
if {[expr [string compare bbb aaa] > 0]} { | |
puts ">" | |
} else { | |
puts "<=" | |
} | |
if {[string equal a a]} { | |
puts "equal" | |
} else { | |
puts "not equal" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment