From: Joe E. <jen...@fl...> - 2006-01-31 19:13:31
|
Andreas Kupries wrote: > touch PATH > Creates empty file at PATH. Deletes any pre-existing > file in this location. For Unix users, "touch" would be a _very bad_ name for this operation -- the shell command `touch` only updates the modification time of existing files, it doesn't truncate them. > getfile PATH > Returns contents of file. Assumes that file is text, > and in system encoding. > putfile PATH TEXT > Writes text as the new content of the file. > Note: Does _not_ add a traling \n to the data. I usually call these "readFile" and "writeFile", after the analogous Haskell Standard Prelude functions. > insertat PATH AT DATA > Inserts data at offset AT into the file. > > removeat PATH AT N > Removes N characters from the file, starting at > offset AT. No comment on the names, but these operations would be very useful to have in tcllib just so we'd have a short answer when newbies ask how to do this (which seems to come up once a month or so on c.l.t. :-) > hack_file PATH KEY VAL ... > Takes the list of keys and values and applies them to > the contents of the file, via [string map]. > > hack_file_copy PATHin PATHout KEY VAL ... > Like hack_file, but writes the result to a different > file. These seem rather special-purpose. A useful factor of the first one might be: updateInPlace $filename $cmdPrefix -- Reads the contents of file $filename and passes it as an additional argument to $cmdPrefix. Overwrites the original file with the return value of the command. If the command raises an error, the original file is not modified. Then 'hack_file' could be expressed as: updateInPlace PATH [list string map [list KEY VAL...]] --Joe English jen...@fl... |