Writing an Array Variable to a File
There are many times when you would like to save the value of an array so that you can analyze its results at a later time. The following macro writes an array's value to a file and saves it.
proc save_to_file { var fname } {
set values [capture dprint $var]
set f [open $fname w]
puts $f $values
close $f
}
The following shows how you might use this macro. Notice that using the exec command lets cat display the file that was just written.
d1.<> dprint list3
list3 = {
(1) = 1 (0x00000001)
(2) = 2 (0x00000002)
(3) = 3 (0x00000003)
}
d1.<> save_to_file list3 foo
d1.<> exec cat foo
list3 = {
(1) = 1 (0x00000001)
(2) = 2 (0x00000002)
(3) = 3 (0x00000003)
}
d1.<>