# Handling tcl files in ruby

**URL:** <https://www.ruby-forum.com/t/handling-tcl-files-in-ruby/150137>\
**Category:** Ruby\
**Created:** [October 4, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/handling-tcl-files-in-ruby/150137 "2008-10-04T12:46:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![salamond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@salamond](https://www.ruby-forum.com/u/salamond)\
**Post date:** [October 4, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/handling-tcl-files-in-ruby/150137/1 "2008-10-04T12:46:07Z")

</div>

Hi, all.

Here’s the problem occurred to me.

I’m having several tcl files like this:

data {  
name {jarod}  
id {1131321}  
}

data {  
name {hhhh}  
id {2929292}  
}

I defined a couple of proc like proc data, to auto generate arrays for  
me.  
(arrays in tcl is like hash in ruby)  
I just source file\_name in my tcl\_project, so that those arrays are  
generated automatcially.

because of this, I might have something like :  
data {  
name {jarod}  
id {123455}  
}  
source a.tcl ;# a.tcl is another data file

Now I have to let ruby understand all these data files.

Options that I’m having:  
1 translate all data files to xml, let ruby parse xml files  
I’ve already tried the first one, but the result isn’t so good,  
new xml files are hard to understand and maintain.  
2 write my own ruby parser,  
I’ve tried google, there seems to be a couple of ruby parser on  
rubyforge. not look into it till now.  
3 call tcl in ruby to parse all those files.  
I’ve found that there’s no tcl\_array\_to\_ruby\_hash function  
available in ruby/tk package.

I think the best way is to keep the current format, but I’m not sure  
if it is the right thing to do.  
so does any body have experiences on this kind of staff or any  
suggestions or ideas?

thanks

JaordZZ

---

<div class="post-metadata">

**Author:** ![salamond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@salamond](https://www.ruby-forum.com/u/salamond)\
**Post date:** [October 4, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/handling-tcl-files-in-ruby/150137/2 "2008-10-04T17:54:30Z")

</div>

salamond wrote:

> because of this, I might have something like :  
> 1 translate all data files to xml, let ruby parse xml files  
> if it is the right thing to do.  
> so does any body have experiences on this kind of staff or any  
> suggestions or ideas?

Suggestion: look for a json (or yaml) emitter in tcl, or write one (it  
should be easy–a limited ruby json emitter is about 50 LOC). Dump your  
tcl structures to json, and that can be loaded in ruby using any of the  
ruby json libs.
