From: matt@... (matt neuburg) Date: 2009-04-01T01:14:52+09:00 Subject: Re: Array read to seperate items matt neuburg wrote: > Stuart Clarke wrote: > > > I have an array which gets data added to in a loop like so: > > > > a b c d e f > > a b c d e f > > > > I am aware calling join("\n")on this array will separate each line of > > the array with a new line, but I want to separate the individual items > > and load them into there own arrays for example > > > > array a = a, a > > array b = b, b > > Are you talking about something like this? > > arr = ["hey ho hey nonnie no", "bee bop a ding dong", "a b c d e"] > arr = arr.map {|s| s.split(" ")} > arr = arr.shift.zip(*arr) Last line cute but unnecessary, forgot about "transpose" (see msg from Rob B.): arr = ["hey ho hey nonnie no", "bee bop a ding dong", "a b c d e"] arr = arr.map {|s| s.split(" ")}.transpose p arr #=> [["hey", "bee", "a"], ["ho", "bop", "b"], ["hey", "a", "c"], ["nonnie", "ding", "d"], ["no", "dong", "e"]] m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com