Bryan W. wrote:
I edited your code and just changed a couple lines:
I changed this:
input_file_stream = File.open(input_filename, “r”)
input_file_stream = IO.readlines(input_filename)
Using IO.readlines will just read the entire contents of the file and
each line as an element in an array. You can then iterate through the
rather than using a while loop.
I changed your loop and changed the line where you split the lines of
csv file from this:
input_file_line = input_file_stream.gets.to_s.split(/,/)
input_file_line = line.split(/,/)
This should work, I obviously did not test it. Hopefully this will
you in the right direction.
Thanks everyone for helping me out. I really appreciate your help.
As I said previously, the CSV file is not constant â€” no used as a
database-like file. Here’s an exemple of the data :
Every single line begins by the same string. However, the first and the
last lines differ from each other. Also, the middle lines are also
different from the first.
That is why I read the first line as being the headline and then going
through a loop till EOF. I achieved this part. It’s working great the
way I did it. However, I would like my loop to stop on the string
“Total:” which is part of the last line only.
The reason why I need to stop on that particular word is that I will
have many of the first lines, middles lines and last lines for specific
people in the same file.
That is why I could not use MySQL to import the CSV file and that (I
think) using FasterCSV wouldn’t help that much either. I also want to
automate processes the more I can.
Hope this can help to help me Maybe I am not doing it the way I
should be. I have to mention that I’m new with Ruby but, I love it.
Have a good day everyone!