1

I have a test.tcl file that sources another common.tcl file which contains common procs. Here's a sample content of the common.tcl :

set top_path  path.to.top
set path_a    $top_path.a

proc x { level } {
  if { $level == "top" } {
    puts $top_path
  }
  if { $level == "a" } {
    puts $path_a
  }
}

proc y {
  puts $env(WORKAREA)
}

And here's how the test.tcl looks like :

source $env(PATH_TO_COMMON)/common.tcl
x top
y

The error I'm getting is that the variables (the ones set at the topmost 2 lines of common.tcl) and even the environment variable WORKAREA could not be read (no such variable). No matter if I use set ::env(top_path) and try to read it inside the proc as puts $::env(top_path), I see the same error. Any simple way to resolve this ? There are many lines of setting variables that I need to update.

2
  • I don't have time for an actual answer, but read up on the global and variable commands. Commented Feb 14, 2023 at 10:43
  • Why don't you read the global variable in a proc with $::env($::top_path) ? Commented Feb 15, 2023 at 3:21

1 Answer 1

2

I don't fully understand your question. How about re-write the script like the following? Add global namespace qualifier :: before the variable names. Also add $ before variable level. And use "eq" instead of "==".

set top_path  path.to.top
set path_a    $top_path.a

proc x { level } {
  if { $level eq "top" } {
    puts $::top_path
  }
  if { $level eq "a" } {
    puts $::path_a
  }
}

proc y {
  puts $::env(WORKAREA)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.