I am trying to read a file which contains some numbers. And then i want to convert them into integer. When i'm trying like below, it is ok.
input = IO.readlines(filename)
size = input[0].split(/\s/).map(&:to_i)
But, when i'm trying like below, it gives me that error.
input = IO.readlines(filename)
lnth = input.length
i=0
while i<=lnth
size = input[i].split(/\s/).map(&:to_i)
i=i+1
end
undefined method `split' for nil:NilClass (NoMethodError)
How I solve the error now?
Obviously while i<lnth
not <=
:
while i<lnth
size = input[i].split(/\s/).map(&:to_i)
i=i+1
end
but preferably use:
size = line.split(/\s/).map(&:to_i)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With