From: Carlos Date: 2001-12-30T09:18:06+09:00 Subject: [ruby-talk:29676] Re: comma-delimited to an array > > I've got a file in which each line has comma-delimited items. A > > sample might look like this: > > > > num,date,time,orig,type,action,rule,iface > > 1,28Dec2001,23:59:51,121.210.49.22,log,accept,16,eth-s1p2c0 > > 2,28Dec2001,23:59:44,121.210.48.11,log,drop,20,eth-s1p1c0 > > 3,28Dec2001,23:59:57,121.210.49.22,log,accept,16,eth-s1p1c0 > > > > But the question is, as I read each line, how do I convert that > > single line into an array? > > array=line.split(",") And remember to #chomp the line before, or your last field will end in "\n". So: array=line.chomp.split(",")