#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4

    Trouble with Dereference


    I have an array of a reference to arrays that contain objects, or hashes. How do I dereference the hash elements for use?

    So in one module I create my objects and put them into 3 array's and pass a reference to those array's into another module. In that module I'd like to work on what I need in one loop so I pushed the 3 array references into a local array and am trying to use a nested for loop to do the work. I can't access the hash elements or objects that I need. I'm close as I've seen the object name and hash key printed just can't get the value. Please help, hope this makes sense, its late.

    $new_array[$i]$[$j]{ELEMENT} is where I see the hash keys.

    I figured local array doesn't need to be dereferenced only the 2nd array and hash?? I only need to work on one hash key so I'd prefer to just call it by name. I do not need the whole hash for this operation.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    I do not understand what your problem is.

    $new_array[$i]$[$j]{ELEMENT} is where I see the hash keys.
    If you "see" the keys (whatever that really means), why can't use them?

    Please print what this gives you, then we can help you adding the next level of dereferencing.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4
    $new_array[$i]$[$j]{element I want} prints

    object_name=HASH(0xaddress)00]{KEY_NAME}

    I want the value of that KEY.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    Code:
    $new_array[$i]$[$j]{element I want}
    Don't need that red one.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4
    I'm getting, "Not an Array reference. Here's a re-cap:

    1. Created objects of 3 different types.
    2. Loop through the object code to create multiple objects of each type and push them into 3 different array's, one for each type.
    3. Pass those 3 array's by reference into another module.
    4. In that Module I put the 3 references into a local array so i can work on them in one nested for loop.

    I cannot access the values, just the Keys and addresses get printed to the screen. I only need 1 key for each object for this function.

    So I need to derefernce an array of references to arrays that store objects or hashes.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,971
    Rep Power
    1225
    Just a guess, since you haven't show us the code that builds the data structure, try this:

    $new_array->[$i][$j]{element I want}
    If that doesn't give you want, then use the Data::Dumper module to dump out the data structure so you can see if it's constructed the way you think.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4
    Thanks guys I got it to work but am confused. To get it to work i just needed $array->[$j]{ELEMENT} and one for loop. I changed things a little such that I'm passing a reference of the new array into a sub, since eventually thats what i want to do anyway, as opposed to just straight working on the new array. I'm surpresed this works because I thought I was 3 deep meaning ref_array0->ref_array1->my data. When you pass references of arrays to one big array does it just create an element for every reference? I'm confused as to why this works for me.

IMN logo majestic logo threadwatch logo seochat tools logo