Code: Select all
## Operation Procedures
proc prc_addsite {site} {
global sitefile
if {[catch {open $sitefile a} fd]} {
return 0
} else {
puts $fd $site
close $fd
return 1
}
}
Code: Select all
set fd [open thefile "RDONLY"]
set tmp [split [read -nonewline $fd] "\n"]
# Read the data, and split it on newlines...
close $fd
set fd [open thefile "WRONLY CREAT TRUNC"]
# Re-open the file in write-only mode, creating the file if it's missing, and clearing any previous content.
puts $fd [join [lrange [linsert $tmp 0 $data] 0 9] "\n"]
# Insert $data at the beginning of the list, then trim the list to the first 10 items, and finally join it back into a textstring, separating each list item with a newline. Write it back into (the empty) file.
close $fdCode: Select all
set fd [open thefile "RDONLY"]
set tmp [split [read -nonewline $thefile] "\n"] Code: Select all
set fd [open thefile "RDONLY"]
set tmp [split [read -nonewline $fd] "\n"]