Catalog / Tcl Programming Cheatsheet
Tcl Programming Cheatsheet
A quick reference guide to the Tcl scripting language, covering syntax, commands, and common usage patterns.
Tcl Basics
Syntax Fundamentals
Command Structure |
Commands are space-separated. |
Variable Assignment |
Assigns a value to a variable. |
Variable Substitution |
Substitutes the value of a variable. |
Command Substitution |
Executes a command and substitutes the result. |
Comments |
|
Quoting |
|
Basic Commands
|
Prints a string to the standard output.
|
|
Assigns a value to a variable.
|
|
Evaluates an expression.
|
|
Conditional execution.
|
|
Looping construct.
|
|
Defines a procedure.
|
Control Flow and Procedures
Conditional Statements
if-elseif-else
|
switch
|
Looping Constructs
|
|
|
|
|
Exits the current loop.
|
|
Skips the current iteration and continues with the next.
|
Procedures (Functions)
Procedure Definition
|
Calling a Procedure
|
Example
|
Variable Scope - By default, variables are local to the procedure. Use
|
String Manipulation and Lists
String Operations
|
Returns the length of a string.
|
|
Returns the character at a specific index.
|
|
Extracts a substring.
|
|
Compares two strings.
|
|
Converts a string to lowercase.
|
|
Converts a string to uppercase.
|
List Manipulation
|
Creates a list.
|
|
Returns an element from a list by index.
|
|
Returns the length of a list.
|
|
Appends elements to a list.
|
|
Inserts elements into a list at a given index.
|
|
Replaces elements in a list.
|
File I/O and Regular Expressions
File Input/Output
|
Opens a file.
|
|
Reads data from a file.
|
|
Writes data to a file.
|
|
Closes a file.
|
|
Reads a line from a file.
|
Regular Expressions
|
Matches a regular expression against a string.
|
Example: Matching |
|
Example: Capturing |
|
|
Substitutes regular expression matches.
|
Example: Substitution |
|