Posted to tcl by Stu at Thu Jun 08 09:59:44 GMT 2023view raw
- $ cat q.tcl
- # Filters
- package require tov
- set reader [::tov::FileReader new in.txt]
- set filter1 [::tov::FilterDoer new]
- set filter2 [::tov::FilterDoer new]
- set writer [[::tov::FileWriter new out.txt] cascade { configure -buffering none ` yourself }]
- $reader sender [format {%s value $value} $filter1] ;# One way to do it.
- $filter1 sender "$filter2 value \$value" ;# Another way. Neither are pretty.
- $filter1 calculator {string toupper $value}
- $filter2 cascade [format {
- calculator {regsub -all {\.} $value "!"}
- ` sender {%s value $value}
- } $writer]; # Meh for usability.
- $reader value -1 ;# Go.
- $reader destroy
- $filter1 destroy
- $filter2 destroy
- $writer destroy
- # EOF
- $ cat in.txt; tclsh8.6 q.tcl; cat out.txt
- A Tcl script is a string containing one or more commands.
- A TCL SCRIPT IS A STRING CONTAINING ONE OR MORE COMMANDS!