It often occurs that you want to save the value of an array so that you can analyze its results at a later time. The following macro writes array values to a file:
proc save_to_file {var fname} {
set values [capturedprint$var]
set f [open $fname w]
puts $f $values
close $f
}
The following example shows how you might use this macro. Using the exec command displays the file that was just written.