Jason, I think you can do better with Faster CSV gem. You can read (slurp) the entire csv into array of arrays (two dimensional). like zo...
require 'fastercsv' mydata = FCSV.read('filename.csv') now you can do whatever you need with mydata because it's a 2D Array[][] http://fastercsv.rubyforge.org/ another solutions is persist data in yaml file and read it with YAML builtin lib. http://yaml4r.sourceforge.net/cookbook/ On 6/28/07, Jason Naylor <[EMAIL PROTECTED]> wrote:
What's your preferred method and code for looping through source files? Essentially, each row within my source file represents a bunch of variables I want to use - whether they be various usernames/passwords for login; information on various fields on my screen I want to assert; etc. I've used the following (once) previously with success, but I don't feel it's the optimal code. Surely there's an easier, simpler way within Ruby? Problem is I'm just trying to learn. userpass_file = IO.readlines('xxx_INPUT_FILE_xxx') i = 1 #start on second line (line 1), the first line (line 0) is column headings while i < userpass_file.length do array = CSV.parse_line(userpass_file[i]) varable1 = array[0] variable2 = array[1] variable3 = array[2] DO YOUR STUFF WITH THE VARIABLES i = i +1 #increment for the next line end Maybe the CSV parser will do a better job??? (My source file is currently a CSV if that helps.) - Jason _______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general