From: Xavier Noria Date: 2008-05-02T06:25:36+09:00 Subject: Re: parsing a file On Thu, May 1, 2008 at 11:07 PM, Adam Masiarek wrote: > Input file format (three columns, tabs delimited): > A \t X1, X2 \t Z1, Z2 > B \t X3 \t Z3 > C \t X4, X5, X6 \t Z4, Z5, Z6 > > Expected file format: > A X1 Z1 > A X2 Z2 > B X3 Z3 > C X4 Z4 > C X5 Z5 > C X6 Z6 > > My code: > a = Array.new() > x = Array.new() > z = Array.new() > s = String.new() > open("c:\\temp\\a.txt").each {|e| > a = e.split("\t") > x = a[1].split(",") > z = a[2].split(",") > x.each_index {|i| > s = a[0] +"\t" + x[i] +" \t" + z[i] > puts s > } > } > > > Can this be done in a more elegant manner? The approach is OK, these are mostly cosmetic touches: input = <