我有一个 txt 记录文件:
firstname lastname dob ssn status1 status2 status3 status4 firstname lastname dob ...
我可以把它变成一个数组:
tokens[0] = firstname
...
tokens[8] = firstname (of record 2).
tokens[9] = lastname (of record 2) and so on.
我想逐步迭代tokens
数组,所以我可以说:
record1 = tokens[index] + tokens[index+1] + tokens[index+2] etc.
并且该步骤(在上面的示例 8 中)将处理记录:
record2, record3 etc etc.
step 0 index is 0
step 1 (step set to 8 so index is 8)
etc.
我想我应该说这些记录来自我称为 .split 的 txt 文件:
file = File.open(ARGV[0], 'r')
line = ""
while !file.eof?
line = file.readline
end
##knowing a set is how many fields, do it over and over again.
tokens = line.split(" ")