Short, specific examples would be nice.
The key notion that you need to wrap your mind around is references. (See perlref.)
A “reference” is a Thing, that “refers to” another Thing somewhere else. So when you have “an array of hashes,” the more proper way to say it is that you have “an array of hashrefs.” (The word, “hashref,” is simply a shorthand way of saying, “a reference to a hash.”) So, the data structure itself, is over here, and there are lots of “references to” that data structure scattered about in other places. (Think about that for a little while, until the light-bulb pops on. And I don’t mean that to sound condescending.) It’s very much like “pointers,” but considerably more sturdy.
Arbitrarily complex data-structures can be built using this mechanism. You might need to read up on weaken in Scalar::Util, but that’s another idea for another day...
There are several ways to write this code, and all of those ways work equally well. It’s quite important to use use strict and use warnings when writing this kind of code, but otherwise, Perl is quite generous and forgiving in its syntax rules.
|