L
Li Chen
Hi all,
I use the following script to read a file and create a 2D array.
What bothers me is that I have to use a temporary variable. I wonder if
there is a better way to read a file and create a 2D array.
Thanks,
Li
##################
# create a 2D array
def file_process
@data=[ ]
# read in the file line by line
File.open(@file) do |a_file|
temp=[]
a_file.each_line do|a_line|
a_line.chomp!# remove \n
temp=a_line.split(/\t/) # tab is the separator
@data << temp
temp=[]
end
end
end
I use the following script to read a file and create a 2D array.
What bothers me is that I have to use a temporary variable. I wonder if
there is a better way to read a file and create a 2D array.
Thanks,
Li
##################
# create a 2D array
def file_process
@data=[ ]
# read in the file line by line
File.open(@file) do |a_file|
temp=[]
a_file.each_line do|a_line|
a_line.chomp!# remove \n
temp=a_line.split(/\t/) # tab is the separator
@data << temp
temp=[]
end
end
end