Purpose: to collect pointers and observations regarding techniques for reading and writing configuration files by an application
bach: lvirden: what I like to do is using arrays. Writing: puts array get. Reading read eval array set
lvirden: That's a pretty common technique. That's why I was surprised not to find a page describing that as well as some of the other techniques (like option, etc.)
lvirden: I think that perhaps there are just so many different techniques that we haven't gotten even a small percent of them documented.
suchenwi: But, as I found out, source also works on pure data, so you can write:
array set x [source x.dmp]
Only you cannot have comments in the data then - or you can, if you accept an array element by the name of #, the , then you can dump
# {Saved by ... on ...}
But, as I found out, source also works on pure data, so you can write:
array set x [source x.dmp]
rmax: It's downside is, that this kind of configuration file isn't very readable or edirable.
suchenwi: Oh, you could format it like this:
foreach i [lsort [array names a]] { puts [list $i $a($i)] }
That's actually what I do, so the file still is nice to browse.
aku: config files - There was a page about tcl patterns somewhere. I believe this contained something. also look for the pages by Koen Van Damme on the wiki
aku: His homepage refers to a paper by him about parsing data files
rmax: Hmm, reading and writing configuration files of various flavour seems me worth spending a tcllib module for. I could add a package that parses windows-style .ini files, I once wrote.
See Metakit