Tcl introduction and features, Tcl introduction features
【Introduction | features]
LIntroduction
Tcl was a language developed from the end of 1980s. Like Python, it was developed from c. If C/Java/C ++/C # Is a compiled language, python, Perl, and Tcl are an explanatory language. That is to say, the program can run directly without first compiling the binary code that the machine can recognize and then running the program. The technical implementation mainly relies on the library in Tcl as the parser. If you know Python, the execution process is as follows: python first compiles the code into bytecode, and then implements the interpretation of bytecode.
As an interpreted language, Tcl also relies on its built-in analyzer for interpretation. the advantage of a compiled language is that it directly processes the CPU instruction set to generate a machine-identifiable binary code, so the speed is very fast and the execution speed after compilation is much faster than that of an interpreted language, disadvantage: the encoding is relatively complex and the amount of code is large. Interpreted language sacrifices the speed, improves the encoding efficiency, and achieves the same function. It uses scripting languages such as Python and Tcl, the Code volume is equivalent to 1/3 ~ of the compiled language C/C ++/Java ~ 1/5, that is, very powerful functions can be achieved with a small amount of code!
Tcl is short for tool command language (tool command language). It is a common scripting language that can run on almost all platforms. It is powerful, easy to learn. Tcl is often used for rapid prototyping, Script Programming, GUI and testing. Tcl is pronounced as "tickle" and consists of two parts: the language itself or an extension library.
First, Tcl is a simple language used to publish commands to interactive programs (text editors, debuggers, and shells). It has simple syntax and strong scalability, tcl can create new processes to enhance its built-in capabilities.
Secondly, Tcl is a library that can be embedded into applications. The Tcl library contains a analyzer, routines used to execute built-in commands, and extensible library functions.
LFeatures
Like Python, Tcl is also known as the "glue" language. It is highly cohesive! If Python does not provide the function provided by library files, you can use the C language to implement this function and then integrate it. The same is true for Tcl. One important feature of Tcl is its scalability. If a program needs to use some functions not provided by the standard Tcl, you can use the C language to create some new Tcl commands and integrate them easily. Tk is a series of commands and processes that make Tcl easy to write graphical user interface GUI. Another popular extension package is rabbitct. which provides the ability to automatically execute commands through terminals, such as command-driven shells such as passwd, ftp, and telnet ).
Well, here we will briefly summarize the above: Tcl is actually a tool language composed of commands. There is only one type of cross-platform, that is, the character type, which is integrated with the operating system, easy to learn.
Let's take a look at the code for connecting devices:
Spawntelnet 192.168.0.2 # login Device
Expect CT "Username:" # expected User Name
Send "admin \ n" # send User Name
Login CT "Password:" # expected User Name
Send "XXXXXX \ n" # send Password
Expect CT "3750>" # expected back-to-text display
Send "en \ n"
Reset CT "Password :"
Send "XXXXXX \ n"
CT "3750 #"
Send "ping 192.168.0.3 \ n"
CT "3750 #"
Send "config t \ n"
CT "#"
Send "ip route 123.2.1.1 route 255.255 null0 \ n"
CT "#"
【Download | run]
LDownload and install
1 .:
Http://www.activestate.com/activetcl/activetcl-8-6
2. Choose Control Panel> system and security> system> advanced> environment variable> system variable to add the Tcl directory to the Path:
LProgram running
After installation, you can choose the following methods to run the program. If you want to print Hello, World, this is the first simple program to learn any language.
Method 1: Run tclsh or tclsh86 (shell of the Tcl Application)
Note:
1. tclsh is the shell of the Tcl application.
2. Generally, run tclsh to enter the shell mode. Because tcl8.6 is installed on my Local Machine and Its file name is C: \ Tcl \ bin \ tclsh86.exe, You need to execute tclsh86.
D: \> tclsh86
% Puts "Hello, World! "
Hello, World!
Method 2: Enter the tclsh file. tcl file to run the program.
D: \> tclsh86 hello. tcl
Hello, World!
Method 3: run a simple Tk script through wish
Enter wish or wish86 to run wish.
Enter button. B-text "Hello, World! "-Command exit
Hello, World! You can also write the preceding command to the hello. tcl file.
Run again:
Result output:
Detailed description:
1. Buttons, grid, and pack are commands in Tcl.
2. B Indicates the child component of the button.
3.-text "Hello, World !" Content to be output
4.-background indicates the background color
5.-text color of the foreground button
6.-The font button font "times 12" indicates the 12-pound Times Roman font.
7. components created by grid. B are not automatically displayed. Use grid to display them on the screen.
8. pack. B compression mode. If the grid is placed in the first row of the grid, the first column
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.