Task

(Over)write a file so that it contains a string.



The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.




proc writefile {filename data} {
    set fd [open $filename w]   ;# truncate if exists, else create
    try {
        puts -nonewline $fd $data
    } finally {
        close $fd
    }
}