creating a datastructure from lists

Discussion in 'Perl Misc' started by sal.x.lopez@gmail.com, Aug 14, 2006.

  1. Guest

    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.
    , Aug 14, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    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
    Paul Lalli, Aug 14, 2006
    #2
    1. Advertising

  3. 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...960f2b038e/c6d0263039cab4bf?#c6d0263039cab4bf



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Aug 14, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anony!

    Set DataStructure

    Anony!, Aug 12, 2004, in forum: Java
    Replies:
    2
    Views:
    387
    Anony!
    Aug 13, 2004
  2. Sharp

    Index-based datastructure

    Sharp, Mar 14, 2005, in forum: Java
    Replies:
    1
    Views:
    317
    Chris Uppal
    Mar 14, 2005
  3. Replies:
    3
    Views:
    381
    shakah
    Jun 23, 2005
  4. Santosh

    Datastructure design

    Santosh, Nov 19, 2003, in forum: C Programming
    Replies:
    6
    Views:
    371
    pandy
    Nov 20, 2003
  5. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    390
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
Loading...

Share This Page