Multiple Dimension Arrays

Perl does not have a multiple dimension array. It can do a pretty good job of faking one through the use of anonymous references. (References are discussed in Chapter 6.)

For example:

my @matrix = (
    [ 1,  2,  3], 
    [11, 12, 13], 
    [21, 22, 23] 
); 

$matrix[2][2] = "Sam";

Notice that square brackets are used ([ ]) to declare the rows of the matrix.

At this point in the game, you can pretend that Perl has multiple dimension arrays. For almost everything you’ll write, Perl does the right thing. But for a more detailed description of what’s going on, you have to wait for Chapter 6.

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.