Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to declare a variable globally which is used only in proc

Tags:

tcl

i am having a following code:

proc testList {setupFile ""} {
  if {$setupFile == ""} {
    set setupFile location
  }
}
proc run {} {
  puts "$setupFile"
}

I am getting syntax error. I know if i declare the setupFile variable outside the proc i.e in the main proc then i can append it with namespace say ::65WL::setupFile to make it global but not getting how to do that if a variable itself is defined in the proc only.

like image 502
Sumit Avatar asked Apr 16 '12 18:04

Sumit


People also ask

How do you declare a variable as a global variable?

The global Keyword Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function. To create a global variable inside a function, you can use the global keyword.

How do I declare a global variable in VBA?

To make the variable available for all the Sub procedures across all the modules, we need to declare the variable at the top of the module not by using the word “Dim” but by using the name “Public” or “Global.”


1 Answers

You can refer to the global namespace with ::.

proc testList {{local_setupFile location}} {
    # the default value is set in the arguments list.
    set ::setupFile $local_setupFile
}

proc run {} {
    puts $::setupFile
}
like image 90
glenn jackman Avatar answered Oct 02 '22 18:10

glenn jackman