I have a file that contains chunks of text. (see https://github.com/rochford77/hw2_rochf1rt/blob/master/ClassList).
I need each chunk of code, between the spaces, to be its own array, and an array of words not characters.
I can read the file line-by-line, as an array of words with
in_file_array = IO.readlines('filename.txt')
I have three options, none of which I can figure out. I only need each block of text in an array for a small period of time, so I can print some information to a new file.
- Option 1 is to have the above code stop at a new line, give me the array, let me mess with it, then on the next loop resume after the line until the next one, refilling my array with new information.
- I could also just make a bunch of arrays, one for each chunk between the lines, and give them all different names.
- I could take them in as one huge array, and then cut them into several smaller arrays between the lines.
I cannot seem to get any of the above to work. Could someone please provide some help?
To clarify I need an array that contains something like:
array1 = [PH03, ----, fine1l, howar1s,...]
#do something to array
array1 = [MT03, ----, fine1l, clega1s....]
but reading from the file.