Writing an Array Variable to a File
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 [capture dprint $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 tells the shell’s cat command to 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.<>