Chirag
Chirag

Reputation: 13

How to get value of variable from open file

I am working on TCL script that will open another tcl file and I want to get value of variable from second opened file and use it in the first file.

Two file abc.tcl and xyz.tcl abc.tcl opens file xyz.tcl and reads value of variable and use it in abc.tcl.

Upvotes: 0

Views: 522

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

If xyz.tcl sets a global variable, abc.tcl will be able to see it if it used source to load in xyz.tcl.

Here's a simple example. This is xyz.tcl:

set SomeVariable 12345

This is abc.tcl:

source xyz.tcl
puts "The password on my luggage is $SomeVariable"

The source command is really very simple internally. It just reads in the contents of the file (into a string), and then internally evals that string. Yes, this means that you probably shouldn't put source inside a procedure, at least not unless you're sure what the consequences of this are.

Upvotes: 1

Related Questions