in reply to assigning hash key to reference of array question

When writing code like this, I find that I just have to grab a number-two pencil and a piece of paper and write down what I want the computer to do.   It looks to me like you are unintentionally creating “a reference to a reference.”

When you put a complex piece of data “into” an array or a hash, what actually happens is that you put “a reference to that data” there. “A reference” is, effectively, a scalar.   It is, in other words, “a Thing,” separate from “the other Thing” that it refers to.   You need to be sure that, when the dust settles, you wind up with “two references to the same Underlying Object,” not “a reference to a reference.”

It’s tricky to do.   (Heck, it’s hard enough to explain...)

Replies are listed 'Best First'.
Re^2: assigning hash key to reference of array question
by ikegami (Patriarch) on Feb 28, 2011 at 21:01 UTC

    It's actually very simple to map out data structures. If it's tricky, something has gone wrong.

    A collection of servers is a hash of servers keyed by name.
    A server is a collection of IP addresses.
    A collection of IP addresses is an array of IP addresses in dotted form.

    It looks to me like you are unintentionally creating “a reference to a reference.”

    His structure is fine. The problem is that he was replacing the collection of IP addresses when he wanted to add to it.