Site hosted by Angelfire.com: Build your free website today!
NAME
  global - Access global variables

SYNOPSIS
  global varname ?varname ...?

DESCRIPTION
  This command is ignored unless a Tcl procedure is being interpreted. If
  so then it declares the given varname's to be global variables rather
  than local ones. Global variables are variables in the global namespace.
  For the duration of the current procedure (and only while executing in
  the current procedure), any reference to any of the varnames will refer
  to the global variable by the same name.

EXAMPLE
  % set x 100
  100
  
  % set y 200
  200
  
  % proc p1 {a b} {
      puts "p1(x) = $x"
      puts "p1(y) = $y"
    }
  
  % proc p2 {a b} {
      set x 5
      set y 10
      puts "p2(x) = $x"
      puts "p2(y) = $y"
    }
    
  % proc p3 {x y} {
      puts "p3(x) = $x"
      puts "p3(y) = $y"
    }
    
  % p1 2 2
  can't read "x": no such variable
  
  % p2 2 2
  p2(x) = 5
  p2(y) = 10
  
  % p3 2 2
  p3(x) = 2
  p3(y) = 2


  % set x 100
  100
  
  % set y 100
  100
  
  % proc p1 {a b} {
      global x y
      puts "p1(x) = $x"
      puts "p1(y) = $y"
    }

  % p1 5 5
  p1(x) = 100
  p1(y) = 100

SEE ALSO
  namespace variable