On Tue, 25 Sep 2001 [EMAIL PROTECTED] wrote:

> are there multi-dimensional arrays in perl?

Yes, but not exactly, if you are thinking in terms of multi-dimensional
arrays as they are in C.  In Perl, we build up complex data structures by
using references:

my @multiarray = ( [1, 2, 3, 4], [5, 6, 7, 8]);

Here we have an array comprised of two anonymous arrays (which are
references), but you can use this as if it were a multidimensional array:

print $multiarray[0]->[3]; #would give you 4

print $multiarray[1]->[2]; #would give you 7

The arrow operators here are really optional, so you can even do:

print $multiarray[0][3];

which looks almost like C.  Just keep in mind that you are still using
references and not true multidimensional arrays.


The cool thing about this is that you can make your arrays (and hashes)
arbitrarily complicated, by having an array or array references, an array
of hash references, and so on.

Take a look at the perlref doc for more details on this.

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
The past always looks better than it was.  It's only pleasant because
it isn't here.
                -- Finley Peter Dunne (Mr. Dooley)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to