Forum: Ruby handling tcl files in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae70bcd1b2eb560ec6bf2a565ad1ae31?d=identicon&s=25 salamond (Guest)
on 2008-10-04 12:46
(Received via mailing list)
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
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2008-10-04 17:54
(Received via mailing list)
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.
This topic is locked and can not be replied to.