TCL programming introduction (III)

Source: Internet
Author: User

TCL programming introduction (III)
 

TCL built-in commands

Built-in commands

TCL provides the built-in functions described below.

... Indicates that the parameters are not specific:

APPEND command:

Append varname Value
Append varname value...

 

Append the large number of values to the end of varname. If the variable does not exist, a new one is created.

Example:

Set I "AAA"
Append I "BBB" "CCC"
// I = aaabbbccc

 

Array command:

Array subcommand arrayname
Array subcommand arrayname arg...

 

This is a group of commands for vector operations. The second parameter is the subcommand name.

Hypothesis:

Set a (1) 1111
Set a (2) 2222
Set a (three) 3333

 

Take it as an example (tclsh is running in ).

Array names arrayname

Returns a list of array element names.

Tclsh> array names
1 2 three
Array size arrayname

 

Returns the number of elements in the array.

Tclsh> array size
3

 

The following command is used for traversal.

Arrry startsearch arrayname

Initialize a traversal and return a traversal identifier (searchid) which is used in the following command.

Array nextelement arrayname searchid

Returns the elements in the next array. If no empty string is returned.

Array anymore arrayname searchid

1 indicates that more elements exist. 0 indicates no.

Array donesearch arrayname searchid

End the traversal.

Array nextelement arrayname searchid

Returns the next element.

Tclsh> array startsearch
S-1-a
Tclsh> array nextelement A s-1-a
1111
Tclsh> array nextelement A s-1-a
2222
Tclsh> array anymore a s-1-a
1
Tclsh? Array nextelement A s-1-a
3333
Tclsh & gt; array donesearch A s-1-a

 

Note that multiple traversal operations can be performed concurrently.

Break command
Break

 

Jump out of the latest loop.

Case string in patlist body...
Case string patlist body...
Case string in {patlist body ...}
Case string {patlist body ...}

 

Branch jump.

For example:

Case ABC in {A B} {puts 1} default {puts 2} A * {puts 3}
Return 3.

Case A in {
{A B} {format 1}
Default {Format 2}
A * {Format 3}
}
Returns 1.

Case XYZ {
{A B}
{Format 1}
Default
{Format 2}
A *
{Format 3}
}
Returns 2.

 

Note that default cannot be placed first. Supports matching characters of shell file names.

Catch command

Catch command varname

Used to prevent interrupted execution due to errors. Run the command and tcl_ OK is returned each time, regardless of whether an error occurs. If an error occurs, 1 is returned, and 0 is returned. If varname is given, this is set to an error message. Note that varname is an existing variable.

CD commands (such as shell)
CD dirname

 

Convert the current working directory. If dirname is not provided, it is transferred to the home directory.

Close fileid

Disable the file descriptor.

Concat arg...

Concatenates parameters to generate a table.

Concat a B {c d e} {f {g h }}
Return 'a B c d e f {g h }"

Continue

 

End the loop and continue the loop.

EOF fileid

For example, if fileid ends with 1, otherwise 0 is returned.

 

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.