# Problem with Array

**URL:** <https://www.ruby-forum.com/t/problem-with-array/143349>\
**Category:** Ruby\
**Created:** [July 17, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/problem-with-array/143349 "2008-07-17T16:40:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@drweb](https://www.ruby-forum.com/u/drweb)\
**Post date:** [July 17, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/problem-with-array/143349/1 "2008-07-17T16:40:21Z")

</div>

Hi!

If some one can help me to fix this code. I want to store the value of  
faulty\_array[num] in faulty\_line[i] and correct\_array[num] in  
correct\_line[i] so that I can access them at later stage. I will be  
thankful.

…

faulty\_line=[]  
correct\_line=[]

c\_length=correct\_array.length  
f\_length=faulty\_array.length

c\_length.times do |num|

if correct\_array[num] != faulty\_array[num]

```
faulty_line[i]= faulty_array[num] #problem arises at this line
correct_line[i]= correct_array[num] #problem arises at this line

```

end

end

puts faulty\_line[0]  
puts faulty\_line[0]

---

<div class="post-metadata">

**Author:** ![drweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@drweb](https://www.ruby-forum.com/u/drweb)\
**Post date:** [July 17, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/problem-with-array/143349/2 "2008-07-17T17:26:01Z")

</div>

On Thu, Jul 17, 2008 at 8:35 AM, M. Muzaffar [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> correct\_line=[]
> 
> end
> 
> end
> 
> ## puts faulty\_line[0] puts faulty\_line[0]
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I’m not positive what you are trying to do here. However from the code  
you  
have posted i never changes so you will continuously overwrite  
faulty\_line[i] and correct\_line[i].

If you are trying to correlate line numbers with line data maybe a hash  
would be better? For example:

array\_of\_errors # this would be an array  
error\_line\_numbers # this would be an array

errors = {}

error\_line\_numbers.each do |line\_number|  
errors[line\_number.to\_sym] = array\_of\_errors[line\_number]  
end

of course this also assumes a one to one mapping of the line\_number and  
line\_data arrays.

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)
