# Double array

**URL:** <https://www.ruby-forum.com/t/double-array/91658>\
**Category:** Rails\
**Created:** [April 11, 2007, 7:33am UTC](https://www.ruby-forum.com/t/double-array/91658 "2007-04-11T07:33:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kickflip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7bcc69/32.png) [@kickflip](https://www.ruby-forum.com/u/kickflip)\
**Post date:** [April 11, 2007, 7:33am UTC](https://www.ruby-forum.com/t/double-array/91658/1 "2007-04-11T07:33:07Z")

</div>

Hi,  
I have an ASCII file that looks like:

1 0 3 0 4  
4 3 2 9 8  
3 0 9 9 7

I am able to store each whole line as an seperate array. But I cannot  
find out how I can get the input of that file and store it into a double  
array. For example, 1 would be array[0][0], and 7 would be array[4][2].

Thank you.

---

<div class="post-metadata">

**Author:** ![kickflip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7bcc69/32.png) [@kickflip](https://www.ruby-forum.com/u/kickflip)\
**Post date:** [April 11, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/double-array/91658/2 "2007-04-11T13:40:43Z")

</div>

Hi Johnathan,

> I have an ASCII file that looks like:
> 
> 1 0 3 0 4  
> 4 3 2 9 8  
> 3 0 9 9 7
> 
> I am able to store each whole line as an seperate array. But I cannot  
> find out how I can get the input of that file and store it into a double  
> array. For example, 1 would be array[0][0], and 7 would be array[4][2].

Are those spaces separating each item, or did you just put that in for  
readability? No worries, it’s similar either way.

Assuming you’ve already used readlines() to read all the file’s lines  
into an array you can then do this:

array.map! do |line| line.split // end

Splitting on an empty regexp divides a string into individual  
characters. But for space-delimited characters you can just use the  
default split using whitespace, which makes things even easier:

array.map! do |line| line.split end

Regards,  
Dave
