Prev: file stat and mode on Windows
Next: protobuf
From: Helmut Jarausch on 20 Jan 2010 04:54 Unfortunately, I don't have experience in programming in Tcl. In an old script there is $mh(hold_fh) insert $msg rename $msg "" foreach u [$mh(hold_fh) list "%u"] { if {![info exists uids($u)]} { break } } Is the loop variable 'u' defined here regardless how the loop was exited? set mh(old_backup) $u I get an error message: can't read "u": no such variable while executing "set mh(old_backup) $u" Is there a change w.r.t. to earlier versions of Tcl (I'm using 8.5.8 currently) Many thanks for your help, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany
From: Arjen Markus on 20 Jan 2010 06:08 On 20 jan, 10:54, Helmut Jarausch <jarau...(a)igpm.rwth-aachen.de> wrote: > Unfortunately, I don't have experience in programming in Tcl. > > In an old script there is > > $mh(hold_fh) insert $msg > rename $msg "" > foreach u [$mh(hold_fh) list "%u"] { > if {![info exists uids($u)]} { > break > } > } > > Is the loop variable 'u' defined here regardless > how the loop was exited? > > set mh(old_backup) $u > > I get an error message: > > can't read "u": no such variable > while executing > "set mh(old_backup) $u" > > Is there a change w.r.t. to earlier versions of Tcl > (I'm using 8.5.8 currently) > > Many thanks for your help, > Helmut. > > -- > Helmut Jarausch > > Lehrstuhl fuer Numerische Mathematik > RWTH - Aachen University > D 52056 Aachen, Germany There is nothing speical about variables used in a for-loop. You are not showing the context, however, of where the error occurs. Can you post a more complete fragment? Regards, Arjen
From: Helmut Jarausch on 20 Jan 2010 06:22 On 01/20/10 12:08, Arjen Markus wrote: > On 20 jan, 10:54, Helmut Jarausch<jarau...(a)igpm.rwth-aachen.de> > wrote: > > There is nothing speical about variables used in a for-loop. You are > not showing the context, however, of where the error occurs. Can you > post a more complete fragment? > OK, here is the full procedure proc ComposeStoreBackup {handler schedule} { upvar \#0 $handler mh global option vFolderDef vFolderHold if {![info exists mh(hold_fh)]} { set mh(hold_fh) [RatOpenFolder $vFolderDef($vFolderHold)] } set msg [ComposeCreateMsg $handler \ [list [list X-TkRat-Internal-AutoBackup [clock seconds]]]] foreach u [$mh(hold_fh) list "%u"] { set uids($u) 1 } $mh(hold_fh) insert $msg rename $msg "" foreach u [$mh(hold_fh) list "%u"] { if {![info exists uids($u)]} { break } } if {[info exists mh(old_backup)]} { ComposeRemoveOldBackup $mh(hold_fh) $mh(old_backup) } set mh(old_backup) $u >>>>>>>> HERE ERROR >>>>>>>> can't read "u": no such variable >>>>>>>> while executing >>>>>>>> "set mh(old_backup) $u" if {$option(compose_backup) > 0 && $schedule} { set mh(next_backup) [after [expr $option(compose_backup)*1000] \ [list ComposeStoreBackup $handler 1]] } } Many thanks, Arjen, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany
From: Alexandre Ferrieux on 20 Jan 2010 06:27 On Jan 20, 10:54 am, Helmut Jarausch <jarau...(a)igpm.rwth-aachen.de> wrote: > > > foreach u [$mh(hold_fh) list "%u"] { > if {![info exists uids($u)]} { > break > } > > Is the loop variable 'u' defined here regardless > how the loop was exited? Only if the list iterated on is non-empty: foreach x {} {puts Hey!} puts $x => can't read "x": no such variable So I'd risk that your [...] command returned an empty list/string. -Alex
From: Arjen Markus on 20 Jan 2010 07:13
On 20 jan, 12:27, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Jan 20, 10:54 am, Helmut Jarausch <jarau...(a)igpm.rwth-aachen.de> > wrote: > > > > > foreach u [$mh(hold_fh) list "%u"] { > > if {![info exists uids($u)]} { > > break > > } > > > Is the loop variable 'u' defined here regardless > > how the loop was exited? > > Only if the list iterated on is non-empty: > > foreach x {} {puts Hey!} > puts $x > => can't read "x": no such variable > > So I'd risk that your [...] command returned an empty list/string. > > -Alex Yes, that seems a likely scenario. Print the result of [$mh(hold_fh) list "%u"]. If that is empty, then the variable u is never assigned a value. Regards, Arjen |