Encodes the standard input channel using the rot13 scheme. Output goes to standard output.
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/sh
# exec tclsh "$0" ${1:+"$@"}
proc main {} {
set fromchars ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
set tochars NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm
set map [list]
foreach from [split $fromchars {}] to [split $tochars {}] {
lappend map $from $to
}
puts stdout [string map $map [read stdin]]
}
main
|
Tags: text
Static versus dynamic map generation. This builds up the rot13 map dynamically, which is nice and readable, but not as fast as a static declaration. Since rot13 isn't going to change, you might replace the dynamic map generation with a static map declaration like
Incorrect invocation of tclsh. The first lines of the script should be:
Using TclX. Using the Extended Tcl extension, one could write