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
    }
 }
posted @ 2011-04-19 15:18  greencolor  阅读(126)  评论(0编辑  收藏  举报