K
kazaam
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
this is my file and I need just the name,hobby and home of each one.
Now I read my file:
File.open(myfile).each { |line|
puts line.sub(/name=|hobby=|home=/,'') if line =~/name|hobby|home/
}
Which puts me the entries nicly on my screen. But I have to process them from my script. So I need some kind of an array struct which let's me iterate over each person and let's me use their name,hobby and home values. But how to achieve this? With with variable-typ and how to get the correctly collected?
I wanna talk to them like this:
person.each |entry| do
puts entry.name
puts entry.hobby
puts entry.home
end
but how to achieve this? any idea or suggestion?
bye
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
this is my file and I need just the name,hobby and home of each one.
Now I read my file:
File.open(myfile).each { |line|
puts line.sub(/name=|hobby=|home=/,'') if line =~/name|hobby|home/
}
Which puts me the entries nicly on my screen. But I have to process them from my script. So I need some kind of an array struct which let's me iterate over each person and let's me use their name,hobby and home values. But how to achieve this? With with variable-typ and how to get the correctly collected?
I wanna talk to them like this:
person.each |entry| do
puts entry.name
puts entry.hobby
puts entry.home
end
but how to achieve this? any idea or suggestion?
bye