Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read variable from one file and save it to another

Status
Not open for further replies.

Paradigm6790

Programmer
Jun 4, 2012
1
US
Hello everybody,

I found a very similar question on this site: but they were dealing with it in a manner that I couldn't quite use.

I am in a situation where I have 2 files: foo.tcl and bar.tcl. The problem I have is that I cannot edit "foo.tcl" but I need the contents of a variable in it (There is a provided proc that pauses code at the part I need). I "simply" need to copy the contents of a variable in "foo.tcl" to a variable in "bar.tcl"

Is there a way to do this beyond using the source command?


Thanks
 
When you say that you "need the contents of a variable" from foo.tcl, does that mean that there is a "set varname value" statement in there somewhere?

If that's the case you can easily get it by opening foo.tcl as a text file and using a regexp to find it.

(in case that's what you're asking)
set fid [open foo.tcl r] for example:
Code:
set fid [open e:/ccs-c/dev/tcl/fixupl.tcl r]
set s [read $fid]
close $fid
set m [regexp {(set dirStart)([^\n]*)} $s a b c]

now "c" has the value that the variable "dirStart" was set to.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top