Logo

Programming-Idioms

History of Idiom 26 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-05-06, 21:04:49

Version 4

2015-07-31, 19:28:49

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Code
my @array = (
   [ 1.0, 0.0, 0.0 ],
   [ 0.0, 1.0, 0.0 ],
   [ 0.0, 0.0, 1.0 ],
   "first three slots are a 3x3 identity matrix",
   "fourth and fifth slots contain strings"
);
   
Comments bubble
Perl has only one-dimensional arrays, but since each slot may hold an array, you can make as many dimensions as you want.