Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #26 Create a 2-dimensional array

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

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"
);
   

Perl has only one-dimensional arrays, but since each slot may hold an array, you can make as many dimensions as you want.
X : array (1 .. M, 1 .. N) of Float := (others => (others => 1.0));

New implementation...