From: Jam Date: 2012-06-07T11:41:43+09:00 Subject: Re: Parsing pipe delimited text file & storing in arrays On Jun 6, 2012, at 7:03 PM, ideal one wrote: > Hi, > I have a txt file with pipe delimited as show below. > > An example log file is: > test1|table1|chair1|55.00 > test2|table2|chair2|155.00 > test3|table3|chair3|55.50 > test1|table4|chair4|47.75 > > i want to parse this txt file and my expected out should be > > (i) Total Cost of test1 = 55.00 + 47.75 > (ii) test1 possessed chair1 and chair4 > > How do i achieve this in ruby code, i tried but doing it as array but > how can i add up the price what 'test1' is responsible to pay? > > array = File.read("pipetest.txt").split(",").map(&:strip) > > puts array[1,2] > > -- > Posted via http://www.ruby-forum.com/. Why are you splitting on commas when your delimiter is a pipe?