Re: Commands pipe



israelu@xxxxxxxxxxx wrote:
Want to be able to write
compi {open lines.txt r|read|string trim|split~\n|puts}
instead of
set txt [read [open lines.txt r]]
set lastline [split [string trim $txt] \n]
puts $lastline

Neat, though I think you really meant to write your example as this:
compi {open lines.txt|read|string trim|split~\n|lindex~end|puts}
going by your variable names from the equivalent. :-) Looking in more
detail though, I see that there's a dangling file handle; you might want
to create special syntax to handle automated cleanup of such things
since the alternative is this:
proc K {x y} {return $x}
compi {
open lines.txt|set f|read|K~[close $f]
|string trim|split~\n|lindex~end|puts
}

One of the things I like about Tcl is how easy it is to construct such
advanced syntaxes on top of it.

Donal.
.