Is there a way to create/simulate a 3D (or higher dimension) array in Perl?
I’ve tried to search on the web, but found nothing.
Is there a way to create/simulate a 3D (or higher dimension) array in Perl?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look at perldoc perllol. That stands for “Perl lists of lists”, which is a name for a type of multi-dimensional data-structures.
Consider
@array. If instead of placing simple values in@array‘s elements you place references to arrays, you now have a data structure that can be treated like an array of arrays, or a 2-dimensional array. Want 3d? No problem. You can go to whatever depth you wish.Your imagination and available RAM are the only constraints on how complex the data structure can become or how many dimensions it can hold. It doesn’t even have to be uniform:
How about a linked list:
And all those are only dealing with simple scalar values combined with array-references. You also get to play with hash references, code references, glob references, object references, and even scalar references. There’s a lot of power available.
Additional useful reading materials are perldoc perlreftut, perldoc perlref, and perldoc perldsc (Data Structure Cookbook), as well as the following books: Intermediate Perl, Programming Perl, and even the somewhat dated Mastering Algorithms with Perl.