Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   creating a datastructure from lists (http://www.velocityreviews.com/forums/t899466-creating-a-datastructure-from-lists.html)

sal.x.lopez@gmail.com 08-13-2006 11:23 PM

creating a datastructure from lists
 
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.


Paul Lalli 08-13-2006 11:46 PM

Re: creating a datastructure from lists
 

sal.x.lopez@gmail.com wrote:
> 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


John W. Krahn 08-14-2006 02:42 AM

Re: creating a datastructure from lists
 
sal.x.lopez@gmail.com wrote:
> 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....d0263039cab4bf



John
--
use Perl;
program
fulfillment


All times are GMT. The time now is 01:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.