save vars and arrays

# save vars and arrays
 proc save_state {} {
    uplevel 1 {
        set fh [open $::statefile w]
        foreach v [info vars] {
            if [array exists $v] {
                puts $fh [list array set $v [array get $v]]
            } else {
                puts $fh [list set $v [set $v]]
            }
        }
        close $fh
    }
 }

 # restore
 proc restore_state {} {
    uplevel 1 {
        source $::statefile
    }
 }
原文地址:https://www.cnblogs.com/greencolor/p/2020966.html