On Sep 29, 2007, at 7:40 AM, kazaam wrote:

> I have a file with many entries and much of these I don't need.  
> Let's imagine:
>
> name=arthur
> age=16
> hobby=swimming
> job=dancer
> home=DE
> name=marry
> age=49
> hobby=singing
> job=nurse
> home=US
> name=tom
> age=32
> hobby=crafting
> job=electician
> home=NW
> name=mantra
> age=22
> hobby=reading
> job=cop
> home=FR

they arrayfields gem is going to make this *very* easy and clear:



cfp:~ > cat a.rb
require 'enumerator'
require 'arrayfields' ### gem install arrayfields

re = %r/\s* ([^=]+) \s* = \s* ([^=]+) \s* \n/iomx
kvs = DATA.read.scan re

records = [] and kvs.each_slice(5){|record| records << Arrayfields 
[record]}

records.each{|record| record.each_pair{|key, value| puts "#{ key } : # 
{ value }"}}

__END__
name=arthur
age=16
hobby=swimming
job=dancer
home=DE
name=marry
age=49
hobby=singing
job=nurse
home=US
name=tom
age=32
hobby=crafting
job=electician
home=NW
name=mantra
age=22
hobby=reading
job=cop
home=FR



cfp:~ > ruby a.rb
name : arthur
age : 16
hobby : swimming
job : dancer
home : DE
name : marry
age : 49
hobby : singing
job : nurse
home : US
name : tom
age : 32
hobby : crafting
job : electician
home : NW
name : mantra
age : 22
hobby : reading
job : cop
home : FR


a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama