From: Todd Breiholz Date: 2006-02-03T06:57:36+09:00 Subject: Seeking the Ruby way ------=_Part_7436_16587385.1138917441910 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm just getting my feet wet with Ruby and would like some advice on how yo= u "old-timers" would write the following script using Ruby idioms. The intent of the script is to parse a CSV file that contains 2 fields per row, sorted on the second field. There may be multiple rows for field 2. I want to get a list of all of the unique values of field2 that has more than 1 value for the 1st 6 characters of field 1. Here's what I did: require 'csv' last_account_id =3D '' last_adv_id =3D '' parent_co_ids =3D [] cntr =3D 0 first =3D true CSV::Reader.parse(File.open('e:\\tmp\\20060201\\bsa.csv', 'r')) do |row| if row[1] =3D=3D last_account_id parent_co_ids << last_adv_id[0, 6] unless parent_co_ids.include?(last_adv_id[0, 6]) else if !first parent_co_ids << last_adv_id[0, 6] unless parent_co_ids.include?(last_adv_id[0, 6]) if parent_co_ids.size > 1 puts "#{last_account_id} - (#{parent_co_ids.join(',')})" cntr =3D cntr + 1 end parent_co_ids.clear else first =3D false end end last_account_id =3D row[1] last_adv_id =3D row[0] end puts "Found #{cntr} accounts with multiple parent companies" Thanks in advance! Todd Breiholz ------=_Part_7436_16587385.1138917441910--