First of all, why didn't you post this under "Tcl & Programming Forum" since this is a Tcl programming question?
Your script seems overly complicated. Instead of storing everything in one array, have config data in an array, and the release data in a list. Then you can cycle through the releases using a simple "foreach" statement, and search for releases using "lsearch".
Or, instead of indexing the entries with a number, why don't you use something more descriptive, like the game's name, or an abbreviation for it? Then you won't have to do that loop to shift the higher entries down when you delete.
You shouldn't need loops to read/write your file, either.
To save your release data:
puts $fp [join [array get releases] "n"]
To read your release data:
array set releases [split [read -nonewline $fp] "n"]
(This assumes there is no newline in the release data.. you could use another character like 01 if you want to use newlines. Also, if you make it a list instead of an array, you don't need the "array get" and "array set" parts.)
Also, did you screw up the copy/paste or something? You have a bunch of repeated code.
You seem to have pub_released already, but it just prints out all the releases? Do you want to add a search capability to it? If so, look up "string match" or "regexp" and you'll see what to do.
Also, about your first comment, if you can't find anyone to help you, why don't you go read the Tcl manual yourself? All the commands are explained at
http://tcl.activestate.com and
http://dev.scriptics.com
Just a general note, you might find Tcl programming easier if you use normal indentation. It's certainly easier to read and debug.
Your code:
Code: Select all
proc load_released {} {
global released
if {[file exists $released(datafile)]} {
putlog "Loading Released data from $released(datafile)"
set in [open $released(datafile) r]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {set released($rloop) [gets $in]}
close $in
}
}
Normal code:
Code: Select all
proc load_released {} {
global released
if {[file exists $released(datafile)]} {
putlog "Loading Released data from $released(datafile)"
set in [open $released(datafile) r]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {
set released($rloop) [gets $in]
}
close $in
}
}
See isn't that more sane? Hehe, seriously I don't even understand how you choose where to put your closing braces, they're totally random.