creating a datastructure from lists

S

sal.x.lopez

I need to convert the following lists:

house,doors,knobs,style
house,doors,knobs,color
house,windows,length
house,windows,width

into a datastructure like this;

$ds = {
'house' => {
'doors' => {
'knobs' => {
'style' => "",
'color' => '""
}
},
'windows' => {
'length' => "",
'width' => ""
}
}
};

Does this require the use of recursive calls? Thanks in advance.
 
P

Paul Lalli

I need to convert the following lists:

house,doors,knobs,style
house,doors,knobs,color
house,windows,length
house,windows,width

into a datastructure like this;

$ds = {
'house' => {
'doors' => {
'knobs' => {
'style' => "",
'color' => '""
}
},
'windows' => {
'length' => "",
'width' => ""
}
}
};

Does this require the use of recursive calls?

No, it does not. You can create loop that iterates over every element
in the current line, each time assigning the reference you're using to
the most recently created level of the structure.

Once you've made an attempt, if it doesn't work the way you want, post
here again, including a SHORT but COMPLETE script that demonstrates
your error, and someone can probably help you to fix it.

Paul Lalli
 
J

John W. Krahn

I need to convert the following lists:

house,doors,knobs,style
house,doors,knobs,color
house,windows,length
house,windows,width

into a datastructure like this;

$ds = {
'house' => {
'doors' => {
'knobs' => {
'style' => "",
'color' => '""
}
},
'windows' => {
'length' => "",
'width' => ""
}
}
};

Does this require the use of recursive calls? Thanks in advance.

See this thread posted a few days ago:

http://groups.google.com/group/comp...960f2b038e/c6d0263039cab4bf?#c6d0263039cab4bf



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,200
Messages
2,571,046
Members
47,646
Latest member
xayaci5906

Latest Threads

Top