In Java you can use try with resources to open a file (resource) and
you do not have to take care of the closing of the file. Does tcl has
something like that?
If not is the following a good way to simulate it partly. (I count on
it that there will be no problem with the read.)
if {[catch {set speedtestFP [open ${speedtestCmd} RDONLY]} openError]} {
puts stderr "Could not start speedtest (${openError})"
return
}
for {set i 0} {$i < 1} {incr i} {
gets ${speedtestFP} pingLine
if {[regexp ${checkPing} ${pingLine} -> ping] != 1} {
puts stderr "Could not get the ping value (${pingLine})"
break
}
gets ${speedtestFP} downloadLine
if {[regexp ${checkDownload} ${downloadLine} -> download] != 1} {
puts stderr "Could not get the download value (${downloadLine})"
break
}
gets ${speedtestFP} uploadLine
if {[regexp ${checkUpload} ${uploadLine} -> upload] != 1} {
puts stderr "Could not get the upload value (${uploadLine})"
break
}
showMessage "${ping} ${download} ${upload}" True
storeSpeedtestDo ${ping} ${download} ${upload} \
${::speedtestSleep} ${::intervalSpeedtest}
}
if {[catch {close ${speedtestFP}} closeError]} {
puts stderr "Could not close speedtest (${closeError})"
return
}
In Java I could just use a return, but I can not leave an open
file-pointer.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn:
http://www.linkedin.com/in/cecilwesterhof
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)