A
A
Alexey Bespalov2021-11-25 08:04:17
Perl
Alexey Bespalov, 2021-11-25 08:04:17

Why doesn't perl have 2D arrays?

I understand the language and want to understand it.

In Perl, it is not possible to create an array with arrays as elements. The same applies to hashes. An element of an array or hash can only be a scalar value. Since a reference is a scalar value, it is possible to create an array or hash whose elements are references to arrays or hashes, and thus obtain a structure that can be used as an array of arrays (respectively, an array of hashes, a hash of arrays, a hash of hashes). Thanks to links, it is possible to construct data structures of arbitrary complexity based on arrays and hashes.


Tell me, that in perl you cannot create arrays of arrays and hashes, is this a language limitation or is there any reason for this? Maybe it gives some performance benefit?

After all, even in the C language there are two-dimensional arrays... I want to delve deeper into this interesting language.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Olgeir, 2021-11-25
@Olgeir

Can.
https://oioki.ru/2011/09/perl-massiv-massivov-hesh...

S
Saboteur, 2021-11-25
@saboteur_kiev

You are a bit confusing array of arrays and multidimensional arrays.
And an array of arrays is when the value of a particular element is also an entire array. And in this case, it is problematic to contact him. But it is possible through a link - first we extract the link, then we turn to the nested array.
And it is natural to have multidimensional arrays in a pearl.
Two-dimensional arrays are just an array, in which to access an element, you need to specify two indices - array (x, y).
Or here is a 3D array with three indices array(x,y,z)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question