Tcl/tk basics-3

Source: Internet
Author: User
Let's talk about the set command today.
The SET command is used to assign values to a variable. It requires two parameters: variable name and variable value.
In TCL, you do not need to follow the rules defined first and then used. The parser automatically creates a variable when the first value is assigned. After the value is assigned, you can use the dollar sign $ to add a variable name. # Assign the variable VAR "5"
Set var 5
# This is the output of the parser.
=> 5
# Call puts to output values in the VaR variable
Puts $ VaR
# This is also the output of the parser.
=> 5

Here "#" is the beginning of the comment statement. TCL only supports single line comment.
The SET command can also accept only one parameter. At this time, the set and puts functions the same. Set var 5
=> 5
# Equivalent to "puts $ Var"
Set $ VaR
=> 5

In fact, Tcl is a special scripting language that only deals with strings. The basic principle of its parser is to "replace substitution" with "group grouping"
The so-called "replace" shows that embedded commands are allowed.
"Group" allows multiple words in a parameter.
The replace command is in the form of command substitution, and the embedded command must be enclosed by square brackets "[" and. The TCL parser interprets all the content in square brackets as commands.
Take the SET command as an Example Set Len [String Length testmessage]
=> 11

In this example, the embedded command is "String Length testmessage" (the string command will be mentioned later ). "String" is used to process all string-related operations. Here it is used to detect the length of the "testmessage" string and assign the return value to Len for future use. This combined command is actually equivalent Set Len 11

If multiple commands are nested, the Tcl parser will explain them from left to right in order, as shown in Set Len [String Length [String range test 0 2]
=> 3

The parser first explains the length, but finds that a subcommand is nested in the command, and then starts to explain the subcommand and get the result of "tes, then, the result is treated as the input of the string length command and "3" is obtained"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.