Read .csv file. Cant obtain data

K

Kamarulnizam Rahim

Here is the code i use:

#!/usr/bin/ruby

require 'rubygems'
require 'csv'

ctr = 0
@data = []
CSV.foreach('C:/Users/nizam/test_q.csv') do |row|
@data << row
puts "#{row[0]} | #{row[1]}"
#unless row[1] =~ /^\[x\]
ctr += 1
end

puts "#{ctr} rows"

puts "Hello World"

However, the output came like this:
0 rows
Hello World

Im pretty sure my .csv file has data in it. But when i run this script,
non of the data come out. I wonder why??

Thanks
Nizam
 
B

brabuhr

However, the output came like this:
0 rows
Hello World

Im pretty sure my .csv file has data in it. But when i run this script,
non of the data come out. I wonder why??

Can I assume since you asked another question about converting a CSV
to YAML, you were able to read your file?
["a", "b", "c"]
["1", "2", "3"]
["4", "5", "6"]
["7", "8", "9"]
 
K

Kamarulnizam Rahim

No I havnt. I can compile the script with no prob. But there is no
output. Do you know why? or maybe csv cant be read properly. I stuck
like few hours on this alone.huhu. Thanks for any help

Nizam
 
J

Justin Collins

No I havnt. I can compile the script with no prob. But there is no
output. Do you know why? or maybe csv cant be read properly. I stuck
like few hours on this alone.huhu. Thanks for any help

Nizam
Maybe you can provide a test file for people to try with your code?

-Justin
 
J

Johnny Morrice

At last im able to read the file. It just happen. I copied the old
file and paste it into my ruby192 folder. It works!!. Attached is the
i wish to read.
Thanks for the help guys!! This forum is really helping me a lot

Thanks! I really like helping people; but you've kind of upset me.

You said you are doing this for a job...

With that in mind, would you agree that you're bloody crazy?

It would be like me putting adverts in the paper offering to sort out
people's plumbing. I know nothing of pipes! (well... ;)

Sir, what would you have done if no one had replied to your mails?
Jings man, you'd be buggered!

I'm not saying you're wrong for seeking employment in the booming
CSV conversion market: oh no, no! Go right ahead.

I just think that you are completely mental.

Anyway, enough BS:

Is your client going to put their files into their ruby192 folder too?

I think you'd better think that one through, matey!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top