TCL programming introduction (2)

Source: Internet
Author: User


TCL programming introduction (2)
 

List

A string is interpreted as a list. A list is a result-like string that contains many fields separated by spaces. For example, "Al Sue Anne John" is an example table with four elements. line feed in the list is considered as a separator. For example:

B c {d E {f g h} is a list of three elements: B, c, and {d E {f g h }}.

TCL commands Concat, foreach, lappend, lindex, linsert, list, llength, lrange, lreplace, lsearch, and lsort allow you to operate on the list.

Regular Expression

TCL provides two commands for regular expressions: Regexp and regsub. Here, the regular expression is actually an extended regular expression, which is consistent with egrep.

Supports ^ $. +? > <() | []

Command result

Each Command has two results: an exit value and a string. The exit value indicates whether the command is correctly executed and the string provides additional information. Effective responses are formulated in 'tcl. H "as follows:

Tcl_ OK

The command is correctly executed, and the string gives the return value of the command.

Tcl_error

Indicates that an error occurs and the string provides an error description. The global variable errorinfo contains a human-readable error description and error message used by the global variable errorcode machine.

Tcl_return

The return command is called. The current command (usually a function) must be returned immediately. The string contains the returned value.

Tcl_break

Indicates that the break has been called, and the nearest loop must be immediately returned and jumped out. The string should be empty.

Tcl_continue

This indicates that the continue has been called and the nearest loop must be returned immediately without jumping out. The string should be empty.

TCL programmers generally need to care about the exit value. The TCL interpreter immediately stops execution after an error is detected.

Procedures Function

TCL allows you to use the proc command to expand the command (to define a new command). After the definition, it can be used like other built-in commands.

For example:

Proc pf {STR }{
Puts $ Str
}
PF "Hello World"
There is something that beginners don't pay attention to here. The above definition must be written like that. You cannot write it as follows:
Proc pf {STR}
{
Puts $ Str
}

 

Because proc is actually just a command and ends with a line break or a semicolon, it uses cluster Parameters to pass the function body. Proc is defined as follows:

Proc name ARGs tclcommand
Variables: scalars and Arrays

 

Variable: Scalar and vector (I .e. array)

Vector is an array, while scalar is a variable without the following table.

We use C for analogy:

Int I; // I is a scalar
Int J [10]; // J is a vector.

 

Variables do not need to be defined. They are automatically created when used. TCL supports two types

Variable: Scalar and vector

For example,

Set I 100
Set J (0) 10
Set K (1, 3) 20

 

I is a scalar, and J is a vector.

When referencing:

$ I
$ J (0)
$ K (1, 3)

 

 

 

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.