# External to Internal

**URL:** <https://rubytalk.org/t/external-to-internal/34480>\
**Category:** ruby-talk\
**Created:** [15 January 2007 20:48 UTC](https://rubytalk.org/t/external-to-internal/34480 "2007-01-15T20:48:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_L\_Versteegen](https://avatars.discourse-cdn.com/v4/letter/p/dbc845/32.png) [@Peter\_L\_Versteegen](https://rubytalk.org/u/Peter_L_Versteegen)\
**Post date:** [15 January 2007 20:48 UTC](https://rubytalk.org/t/external-to-internal/34480/1 "2007-01-15T20:48:59Z")

</div>

Hi,

I want to convert data supplied by a file into their corresponding internal values.

I have an external file with data that are in the form "variable name", tab, followed by their value. The 'value 'can be a single number, an array of numbers, or a matrix of numbers, For example, the file might look like this:  
a 2.4  
b 1,0, 3.0, 5.0  
c 5, 6, 11  
d [1, 2], [5, 6], [45,55]

I can get a, b, and c to convert to single values and arrays, thanks to this forum, but I cannot figure out a way to convert d into an array of arrays. Does anyone have any suggestions?

Ideally I would like to match the variable name in the file to the corresponding and same name in the program. Any ideas how to do that?

Thanks

Pete Versteegen

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [15 January 2007 20:59 UTC](https://rubytalk.org/t/external-to-internal/34480/2 "2007-01-15T20:59:24Z")

</div>

Peter Versteegen wrote:

> Hi,
> 
> I want to convert data supplied by a file into their corresponding internal values.
> 
> I have an external file with data that are in the form "variable name", tab, followed by their value. The 'value 'can be a single number, an array of numbers, or a matrix of numbers, For example, the file might look like this:  
> a 2.4  
> b 1,0, 3.0, 5.0  
> c 5, 6, 11  
> d [1, 2], [5, 6], [45,55]
> 
> I can get a, b, and c to convert to single values and arrays, thanks to this forum, but I cannot figure out a way to convert d into an array of arrays. Does anyone have any suggestions?

Just insert an = :

a = 2.4  
b = 1,0, 3.0, 5.0  
c = 5, 6, 11  
d = [1, 2], [5, 6], [45,55]

p a, b, c, d

\_\_END\_\_

Output:

2.4  
[1, 0, 3.0, 5.0]  
[5, 6, 11]  
[[1, 2], [5, 6], [45, 55]]

> Ideally I would like to match the variable name in the file to the corresponding and same name in the program. Any ideas how to do that?

input = \<\<END  
a = 2.4  
b = 1,0, 3.0, 5.0  
c = 5, 6, 11  
d = [1, 2], [5, 6], [45,55]  
END

a = b = c = d = nil  
eval input ## NOT SECURE!  
p a, b, c, d

\_\_END\_\_

Output:

2.4  
[1, 0, 3.0, 5.0]  
[5, 6, 11]  
[[1, 2], [5, 6], [45, 55]]

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
