in reply to Getting out an array within an array
Hello, Oskar! Maybe the following concept will help to crystalize your thoughts and make the possible approaches clear ...
Perl, itself, only has a small handful of very-simple data structures ... a one-dimensional “list” or “array,” ... a “hash” ... a “scalar” ... but(!) ... within all of that ... it also has the all-important concept of a reference.
“A reference” is “a single thing,” just like (say...) an integer or a string, in the sense that “it occupies only one slot in” a scalar or an array or a hash. But it could refer to “anything(!!).” (So, if you have ever wished to be in two places at one time, “references” are darned-close to Willy Wonka’s “Golden Ticket.”)
When you say, “an array within an array,” well ... no such thing exists. What does exist is something much simpler and much more powerful. The array-element in question consists of a reference to ... another (in this case) array.
Here is the “cognitive jump” that you have to jump: on the one hand, “a reference is” a single thing. But on the other hand, that reference can refer to absolutely anything at all. A scalar ... an entire hash ... an entire list ... an entire array ... even itself.
Please wait patiently until “the little light blinks on,” because when it finally does, it will be well worth it. You can in facct build data-structures of arbitrary complexity through judicious application of this “small handful of primitives” that the Perl language gives you. “References” are the “real Golden Ticket” that allows you to pair anything with anything-else.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting out an array within an array
by Anonymous Monk on Oct 02, 2012 at 06:18 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 20, 2012 at 05:34 UTC | |
|
Re^2: Getting out an array within an array
by sokatron (Initiate) on Oct 02, 2012 at 06:37 UTC |