#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
Last Updated on 2020-11-12 by gantovnik
Recent Comments