[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

handling tcl files in ruby

salamond

10/4/2008 10:44:00 AM

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

1 Answer

Joel VanderWerf

10/4/2008 3:52:00 PM

0

salamond wrote:
> 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?

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.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407