#134 Global variable in tcl

set f "This is a global variable";

#This procedure cannot access the global variable f.
proc testproc1 { } {
   catch {puts $f} val;
   puts $val;
}

#This procedure can access the global variable f using the global command.
proc testproc2 { } {
   global f;
   catch {puts $f} val;
   puts $val;
}
testproc1;
can't read "f": no such variable

testproc2;
This is a global variable

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading