Reputation: 173
Is there anyway in TCL to create a file and write to it, without opening and closing it? This is how I'm doing it right now:
set resultFile [open "$logFile.log" w]
puts $resultFile $data
close $resultFile
I'm asking this because I have to perform this operation numerous times and it will help in runtime if I can just pipe the data to the file directly.
Upvotes: 1
Views: 1158
Reputation: 385800
The mechanism for writing to a file requires that it be open. You are correct that repeatedly opening a file can be slow when done in a loop (though, the loop has to be pretty big to notice it).
You don't have to open it before each call to puts
, however. You can open it once at the start of your program and keep it open while the program runs.
Upvotes: 3