Hi.
In order to shuffle the contents of a text file, I read each line of the
text file into an array, and then used the “.shuffle!” command to
shuffle it in place.
The array now contains my shuffled lines. Below is the code I am using:
f = File.open(“somefile.txt”) or die “Unable to open file…”
f.each_line {|line|
contentsArray.push line
}
contentsArray.shuffle!
I now want to write each line of that array to a new line of a text
file, so I can read from it later on in the script. As the machines that
this script will run on don’t have much RAM, I don’t want to keep
everything in an array as this will take up too much RAM, and would
rather read directly from a text file instead.
I can get the array to output to a text file in a shuffled order, but it
does so in a block, with each entry of the array contained by quotes.
Any help would be appreciated!
Thanks