Hi Hunt,

I don't understand what is your need exactly.
Can u specify what is the output that u need??

Try This,

1.txt
-----

name,rollno,city,country
ABC,123,NewYork,US
XYZ,124,Pittsburg,US
LMN,125,Moscow,RUSSIA

_____________________________________________________

f = File.open('1.txt')
a=[]
c = []
b={}
d = []
f.readlines.each do |lines|
  line_arr = lines.strip.split(',')
  a << line_arr
end
c << a.shift
c = c.flatten
a.each do |x|
b[c[0]]  = x[0]
b[c[1]] = x[1]
b[c[2]] = x[2]
b[c[3]]= x[3]
d << b
b = {}
end
puts d.inspect
f.close

----------------
output :

[{"city"=>"NewYork", "name"=>"ABC", "country"=>"US", "rollno"=>"123"}, 
{"city"=>"Pittsburg", "name"=>"XYZ", "country"=>"US", "rollno"=>"124"}, 
{"city"=>"Moscow", "name"=>"LMN", "country"=>"RUSSIA", "rollno"=>"125"}]

if this is not the format u needed, specify what output u need.


Thanks,
Srikanth J
ROR Developer, Chennai

http://srikanthjeeva.blogspot.com

-- 
Posted via http://www.ruby-forum.com/.