Code · 1 file

Sample Tcl File

A Tcl script using lists, procs and format. Every language sample implements the same small program so you can compare them side by side.

Tcl · 414 B

Sample Tcl file

An idiomatic Tcl example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.tcl — first linesTcl
# Sample Tcl script — samplefiles.com
set customers {
    {1 Ada 12500.00}
    {2 Grace 830.50}
    {3 Linus 10000.00}
}

proc isVip {balance} {
    expr {$balance >= 10000}
}

set total 0.0
foreach c $customers {
    lassign $c id name balance
    puts [format "%-6s %10.2f %s" $name $balance [expr {[isVip $balance] ? "VIP" : ""}]]
    set total [expr {$total + $balance}]
}
puts [format "Total: %.2f" $total]

File details

Size
414 B (414 bytes)
MIME type
text/x-tcl
SHA-256
76174636206503373b544f10b19228e8cdbdd656c04d67e7831d191638aba64d
MD5
e83e425cecd15b58d6bdb69aa0a033ce

Download from the command line

curl -L -o sample.tcl https://files.samplefiles.com/code/tcl/sample.tcl

Or check the download in your browser with the checksum calculator.