Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Problem with Array
Muzaffar Hameed
7/17/2008 2:35:00 PM
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]
--
Posted via
http://www.ruby-...
.
1 Answer
Glen Holcomb
7/17/2008 2:44:00 PM
0
[Note: parts of this message were removed to make it a legal post.]
On Thu, Jul 17, 2008 at 8:35 AM, M. Muzaffar <muzaffar@muzaffar.net> wrote:
> 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]
> --
> Posted via
http://www.ruby-...
.
>
>
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)
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem with Array
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password