R
robnewnham
I have come code which is looking for a particular number within a CSV
row (item no 2). If it finds it, I want it to output the row
unchanged - but if it isn't there, I want it to delete the row
entirely.
I can't get the following code to work - can anyone spot my mistakes?
reequire "csv"
def basketExtract
f = File.open('DATA.DAT')
csvr = CSV::Reader.create(f,'|')
# import CSV file and read it.
header = csvr.shift
#removes header character
outfile = File.new('NEWDATA.DAT','w')
CSV::Writer.create(outfile, '|') << header
csvr.each do |csv|
# read each row in the CSV
if csv[1] == 699 #if the branch number is one of the requested
ones.
outrow = csv
else #if it isn't one in the list
next
end
CSV::Writer.create(outfile, '|') << outrow
end
end
row (item no 2). If it finds it, I want it to output the row
unchanged - but if it isn't there, I want it to delete the row
entirely.
I can't get the following code to work - can anyone spot my mistakes?
reequire "csv"
def basketExtract
f = File.open('DATA.DAT')
csvr = CSV::Reader.create(f,'|')
# import CSV file and read it.
header = csvr.shift
#removes header character
outfile = File.new('NEWDATA.DAT','w')
CSV::Writer.create(outfile, '|') << header
csvr.each do |csv|
# read each row in the CSV
if csv[1] == 699 #if the branch number is one of the requested
ones.
outrow = csv
else #if it isn't one in the list
next
end
CSV::Writer.create(outfile, '|') << outrow
end
end