Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials

array of arrays

( categories: )

An array of arrays is a two-dimensional structure that consists in an array whose elements are references to other arrays.

- Static initialization

Example:

@array_of_arrays =  ( [ "one", "two", "three" ],
                      [  4,   5,  6,  7  ],
                      [ "alpha", "beta" ]
                    );

To access the last element of the second array (number 6 in the example):

$element = $array_of_arrays[1][3];

- Dynamic initialization

There are many ways to initialize an array of arrays programatically. Below are a couple of them.


introduction to references

( categories: )

Understanding references is vital to work with complex data structures; that's the reason for this short introduction.

A reference is basically a pointer to another object. It's as simple as that.

A very important fact is that these pointers are stored in scalar variables. As hashes and arrays are basically collections of scalar variables, you can have array or hash elements that are in fact references to other structures; this way you can easily construct structures like array of arrays, array of hashes, etc.

REFERENCE TYPES

There are two types of references:


Syndicate content