TCL programming introduction (5)

Source: Internet
Author: User

TCL programming introduction (5)
 

Lsort-mode list

List.

-Mode:-ASCII

-Dictionary is similar to acsii, but is case insensitive.

-Convert integer to integer for comparison

-Convert real to floating point and then compare

-Command command: Execute Command for comparison.

Open filename
Open filename access

 

Open the file and return a file descriptor.

Access
R w a r + W + A +

 

The definition is the same as that in C. For example, if the first character of the file name is |, the file is opened in the form of a pipe.

Set f [open | more W]
Set f [open/etc/pass R]

Proc name ARGs body

 

Create a new process to replace any existing process or command.

Proc WF {file STR }{
Puts-nonewline $ file Str
Flush $ File
}
Set f [open/tmp/a w]
WF $ F "first line"
WF $ F "second line"

 

Return can be used to return values at the end of the function.

Puts-nonewline fileid string

Write a string to the fileid. If-nonewline is not added, a linefeed is automatically generated.

PWD

Returns the current directory.

Read fileid
Read fileid numbytes

 

Read numbytes bytes from fileid.

Regexp? Switches? Exp string? Matchvar? ? Submatchvar
Submatchvar ...?

 

Execute Regular Expression matching.

? Switches? -Nocase is case insensitive.
-Indices: return the matching interval.

 

For example:

Regexp ^ ABC abcjsdfh
// Return 1
Regexp ^ ABC abcjsdfh
// Return 1
Puts $
// Return ABC

Regexp-indices ^ ABC abcsdfjkhsdf
// Return 1
Puts $
// Return "0 2"

Regsub? Switchs? Exp string subspec varname

Execute Regular Expression replacement and replace the part matching exp in string with the content of subspec.

? Switchs? -All replaces all matched parts. The first child is replaced by default, and the return value is the number of replicas.

-Nocase is case insensitive.

For example:

Regsub ABC abcabcbac EEE B
// Return 1
Puts $ B
// Return "eeeabcabc"

Regsub-all ABC abcabcabc EEE B
// Return 3
Puts $ B
// Return "eeeeeeeee"

Return
Return immediately from the current command.
Proc FF {}{
Return Friday
}

Set a [ff]
// A = "Friday"

Scan string 'format "varname...

Read the value from string to varname.

Seek fileid offset? Origin?

Move the file pointer.

Origin: Start current end

Offset starts from where it starts.

Set varname? Value?

Sets the value of varname or returns the value of varname. If not in a proc command, a global variable is generated.

Source filename

Read the content from filename and send it to TCL for explanation.

Split string? Splitchars?

Splits string into a list. The default Delimiter is blank. You can also use splitchars to set the delimiter.

String subcommand arg...

A string command.

String compare string1 string2

Execute the string comparison in the C strcmp mode. Returns-1, 0, or 1.

String first string1 string2

Find the location of the string2 definition appearance in string1. -1 is not found.

String Length string

Returns the length of a string.

String Match pattern string

Determine whether the string matches pattern. Pattern is given in the unified format of shell file names.

String range string first last

Returns the content from first to last in the string.

String tolower string

Converts string to lowercase.

String toupper string

Converts string to uppercase.

String trim string

Remove the Left and Right spaces of the string.

String trimleft string

Remove the left blank of string.

String trimright string

Remove the right white space of the string.

Tell fileid

Returns the file pointer position of the fileid.

Time Command

Run the command and calculate the time consumed.

Time "ls -- color"
Some file name
503 microseconds per Iteration
Trace subcommand
Trace subcommand arg...

 

Storage of monitoring variables. Many sub-commands are defined, but currently only

Virable.
Trace variable name Ops Command
Name is the name of the variable.
Ops is the operation to be monitored.
R read
W write
U unset

 

The command that is executed when the command condition is met.

The variable name when name1 name2 ops name1 is executed with three parameters. When name1 is a vector, name2 is a subscript, and OPS is the operation performed.

For example:

Proc FF {name1 name2 op }{
Puts [format "% S % s" name1 name2 op]
}
Set a hhh
Trace variable a r {ff}
Puts $
// Return "a r hhh"

Unknown role name

 

Unknown is not part of TCL. When TCL finds an Unknown command, it will check whether there is an unknown command. If yes, it will be called and no error will occur.

For example:

#! /Usr/bin/tclsh
Proc unknown {CWD ARGs }{
Puts $ CWD
Puts $ ARGs
}
// The following is an error command
Sdfdf SDF sdkhf sdjkfhkasdf jksdhfk
// Return "sdfdf SDF sdkhf sdjkfhkasdf jksdhfk"

Unset name...

Delete one or more variables (scalar or vector ).

Uplevel command...

Connect the start parameter (as shown in Concat ). Finally, it is executed in the context specified by level. If level is an integer, the distance in the stack is given (it is to jump to another command environment for execution ). The default value is 1 (the upper layer ).

For example:

#! /Usr/bin/TCL
Proc FF {}{
Set a "FF" // set local
-------------------------
}
Set a "global"
FF
Puts $
// Return "Global"

 

Next:

#! /Usr/bin/TCL
Proc FF {}{
Uplevel set a "FF" // change a in the upper-level Stack
-------------------------------------
}
Set a global
FF
Puts $
// Return "FF"

 

If level starts with # And returns an integer, level indicates the absolute position in the stack. For example, #0 indicates top-level ).

A B C has three commands respectively. below is the call relationship between them,

Top-level-> A-> B-> C-> uplevel level

Absolute position: 0 1 2 3

When level is 1 or #2, it is executed in B's environment.

3 or #0 are all executed in the top-level environment.

Upvar? Level? Othervar myvar? Othervar myvar ...?

Set up connections for variables in different stacks. The level here is the same as the level in uplevel.

For example:

#! /Usr/bin/TCL
Proc FF {name }{
Upvar $ name x
Set X "FF"
}
Set a "global"
FF
Puts $
// Return "FF"

While test body

 

For example:

Set x 0
While {$ x <10 }{
Puts "X is $ X"
Incr x
}

 

The global variables under built-in variables of built-in variables are automatically managed by the Tcl library. It is generally read-only.

Env

Environment variable array.

For example:

Puts $ ENV (PATH)
// Return/bin:/usr/x11r6/bin

Errorcode

 

Some error messages are saved when an error occurs. Use the following format for storage:

Childkilled PID signame msg

Information when a signal is terminated.

Childstatus PID code

Format when a child program exits with a non-0 value.

Childsusp PID signame msg

Format when a subprogram is terminated due to a signal.

None

The error does not contain any additional information.

UNIX errname msg

The format used when a kernel call is incorrect.

Errorinfo

Contains information of one or more rows, and describes the program and information at which the error occurs.

 

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.