Posted to tcl by Stu at Thu Jun 08 09:59:44 GMT 2023view raw

  1. $ cat q.tcl
  2. # Filters
  3.  
  4. package require tov
  5.  
  6. set reader [::tov::FileReader new in.txt]
  7. set filter1 [::tov::FilterDoer new]
  8. set filter2 [::tov::FilterDoer new]
  9. set writer [[::tov::FileWriter new out.txt] cascade { configure -buffering none ` yourself }]
  10.  
  11. $reader sender [format {%s value $value} $filter1] ;# One way to do it.
  12. $filter1 sender "$filter2 value \$value" ;# Another way. Neither are pretty.
  13.  
  14. $filter1 calculator {string toupper $value}
  15.  
  16. $filter2 cascade [format {
  17. calculator {regsub -all {\.} $value "!"}
  18. ` sender {%s value $value}
  19. } $writer]; # Meh for usability.
  20.  
  21. $reader value -1 ;# Go.
  22.  
  23. $reader destroy
  24. $filter1 destroy
  25. $filter2 destroy
  26. $writer destroy
  27.  
  28. # EOF
  29.  
  30. $ cat in.txt; tclsh8.6 q.tcl; cat out.txt
  31. A Tcl script is a string containing one or more commands.
  32. A TCL SCRIPT IS A STRING CONTAINING ONE OR MORE COMMANDS!