Re: Commands pipe
- From: "Donal K. Fellows" <donal.k.fellows@xxxxxxxxxxxxxxxx>
- Date: Sun, 31 Dec 2006 12:06:31 GMT
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.
.
- References:
- Commands pipe
- From: israelu
- Commands pipe
- Prev by Date: Re: Improving i18n support (Was: Re: Christmas
- Next by Date: Re: unicode normalization
- Previous by thread: Commands pipe
- Index(es):