any code example is highly appreciated
set outFile [open myFile.txt w]
puts $outFile [list array set myArray [array get myArray]]
close $outFile
Then simply source myFile.txt to reload the array.
Steve
There's always:
#save
set file [open $filename w]
puts $file [array get myarray]
close $file
#restore
set file [open $filename r]
array set myarray [gets $file]
close $file
You could use an sqlite database table to store the data rather than an
array.
Glenn
if you have a solution to this maybe you can drop me a line or two of sqlite
insert/update/whatever you may have
thanks for your help
"glennh" <gl...@nospam.glennh.com> wrote in message
news:1115414643.f00217ba45e92e541e52b59268da416c@teranews...
Why not use this to save the array:
set outfile [open "somefile" w]
puts $outfile "array set myarray [list [array get myarray]]"
close $outfile
and this to restore it:
source "somefile"
?
Regards,
Arjen
This technique is fast and easy. But the use of "source"
can be dangerous in some situations. If an advisary is able
to modify "somefile" then they will be able to crash your
program or (worse) insert a trojan horse into your program.
This may or may not be a problem, depending on what your
program does and how it is used.
A safer approach would be:
set out [open "somefile" w]
puts $out [array get myarray]
close $out
And
set in [open "somefile"]
array set myarray [read $in]
close $in
Using SQLite gives you the added advantage that the updates
to somefile are atomic. If your program crashes or your
computer loses power in the middle of saving the array, the
content of "somefile" is not corrupted when SQLite is used.
SQLite will also make sure that two separate instances of
the program do not try to write "somefile" at the same time.
If these factors are a concern, then you can use SQLite to
store your array as follows:
sqlite3 db "somefile"
catch {db eval {CREATE TABLE myarray(name,value)}}
db eval BEGIN
foreach {name value} ]array get myarray] {
db eval {INSERT INTO myarray VALUES($name,$value)}
}
db eval COMMIT
db close
Then to restore:
sqlite3 db "somefile"
array set myarray [db eval {SELECT * FROM myarray}]
db close