From: Ken Bloom Date: 2007-12-07T01:10:39+09:00 Subject: Re: Capturing STDOUT from a system call (POSIX) into an array On Wed, 05 Dec 2007 19:38:35 -0500, Venks wrote: > Thanks for your quick reply. I realize that you don't even need to use > split. What I am missing is how to create a 2 dimensional array with > each line contents in an array assuming that they are separated by a > COMMA. > > Let me be more specific. Assume that we have a file under /tmp/test.txt > with the following contents. > > aaa, 10, test1 > bbb, 20, test2 > ccc, 30, test3 > ddd, 40, test4 > > I want to create a 2 dimensional array with each line being an array. > > lines = `cat /tmp/test.txt` will create a single dimensional array by > default. `cat /tmp/test.txt` will create a single string. require 'csv' nested_arrays=CSV.parse(`cat /tmp/test.txt`) --Ken -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/