Reputation: 1141
I would like to write in file like this:
set fh [open $tmpFileName w]
puts $fh "set a [create_object]"
puts $fh "$a proc1_inside_a"
puts $fh "$a proc2_inside_a"
close $fh
But its get the error message, because a
variable will be created when tmpFileName
file will be executed. So I get the error like this:
can't read "a": no such variable
Can you please help me to resolve this?
Upvotes: 3
Views: 186
Reputation: 247182
You just need to use a different quoting mechanism. Double quotes allow command and variable substitution. Braces will keep their contents verbatim (inhibit substutition)
set fh [open $tmpFileName w]
puts $fh {set a [create_object]}
puts $fh {$a proc1_inside_a}
puts $fh {$a proc2_inside_a}
close $fh
Documentation is available:
Upvotes: 3