I'm using the IO.foreach loop to find a string using regular expressions. I want to append the next block (next line) to the file_names list. How can I do that?
file_names = [""]
IO.foreach("a.txt") { |block|
if block =~ /^file_names*/
dir = # get the next block
file_names.append(dir)
end
}
Actually my input looks like this:
file_names[174]:
name: "vector"
dir_index: 1
mod_time: 0x00000000
length: 0x00000000
file_names[175]:
name: "stl_bvector.h"
dir_index: 2
mod_time: 0x00000000
length: 0x00000000
I have a list of file_names, and I want to capture each of the name, dir_index, mod_time and length properties and put them into the files_names array index according to the file_names index in the text.
/file_names*/matches"file_name","some kind of file_name"and"file_namessssssssssss"./\Afile_names/where\Aanchors to the beginning of string,^at the beginning of a line.*means "zero or more of character" which doesn't appear to be what you mean. You seem to be using it as "more stuff", which it isn't.file_names = [""]initializes your array with an empty string already in it. That's probably a mistake, as it should be an empty array:file_names = [ ]. You can append as necessary without the empty string.