Hi, I’m taking this flat file and putting it into a mysql table.
The question is, given the code I will be working from, what’s the Ruby
way
to skip the first line?
Here’s the table
“zip code”, “state abbreviation”, “latitude”, “longitude”, “city”,
“state”
“35004”, “AL”, " 33.606379", " -86.50249", “Moody”, “Alabama”
“35005”, “AL”, " 33.592585", " -86.95969", “Adamsville”, “Alabama”
“35006”, “AL”, " 33.451714", " -87.23957", “Adger”, “Alabama”
“35007”, “AL”, " 33.232422", " -86.80871", “Alabaster”, “Alabama”
“35010”, “AL”, " 32.903432", " -85.92669", “Alexander City”, “Alabama”
“35014”, “AL”, " 33.355960", " -86.27720", “Alpine”, “Alabama”
“35016”, “AL”, " 34.323715", " -86.49278", “Arab”, “Alabama”
“35019”, “AL”, " 34.292540", " -86.63505", “Baileyton”, “Alabama”
“35020”, “AL”, " 33.405559", " -86.95141", “Bessemer”, “Alabama”
“35022”, “AL”, " 33.346817", " -86.95252", “Bessemer”, “Alabama”
“35023”, “AL”, " 33.443039", " -87.01930", “Bessemer”, “Alabama”
“35031”, “AL”, " 34.111425", " -86.53380", “Blountsville”, “Alabama”
“35033”, “AL”, " 33.952939", " -87.02889", “Bremen”, “Alabama”
“35034”, “AL”, " 32.915182", " -87.21488", “Brent”, “Alabama”
“35035”, “AL”, " 33.041166", " -86.95117", “Brierfield”, “Alabama”
“35036”, “AL”, " 33.638150", " -86.91956", “Brookside”, “Alabama”
“35040”, “AL”, " 33.107572", " -86.74996", “Calera”, “Alabama”
“35042”, “AL”, " 32.963486", " -87.13867", “Centreville”, “Alabama”
“35043”, “AL”, " 33.317093", " -86.66295", “Chelsea”, “Alabama”
“35044”, “AL”, " 33.268471", " -86.35582", “Childersburg”, “Alabama”
“35045”, “AL”, " 32.834501", " -86.64355", “Clanton”, “Alabama”
“35046”, “AL”, " 32.894351", " -86.56504", “Clanton”, “Alabama”
Here’s the code I’ll be working from
prepare statement for use within insert loop
sth = dbh.prepare(“INSERT INTO people (id, name, height) VALUES(?, ?,
?)”)
read each line from file, split into values, and insert into
database
File.open(“people.txt”, “r”) do |f|
f.each_line do |line|
name, height = line.chomp.split("\t")
sth.execute(nil, name, height)
end
end
Thanks guys.
Michael L.