INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Read variable from one file and save it to another

Read variable from one file and save it to another

Read variable from one file and save it to another

(OP)
Hello everybody,

I found a very similar question on this site: http://www.tek-tips.com/viewthread.cfm?qid=1609656 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

RE: Read variable from one file and save it to another

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close