Guide to Understanding Two And Multidimensional Arrays in Perl

Google+ Pinterest LinkedIn Tumblr +

If you have ever tried to read and understand two and/or multidimensional arrays from the Perl official site, then you might not have understood. What is in the Official site can be studied and organized as a set of simple rules, so that the learning of Perl arrays becomes as simple as the learning of arrays in other programs. That is what I have done; and I hope you will appreciate my efforts.

The information in manuals or specifications of languages in the official site is generally written for the inventors and experts. You do not have to be an inventor or an expert in order to work. So you do not have to learn from the official site; and do not be ashamed of that. You have to learn from a simplified source like that one I introduce to you. I have written a tutorial on two-dimensional array in Perl (ActivePerl). The same rules can be extended to three and multidimensional arrays.

Let me now say what is in the tutorial.

The tutorial begins effectively by saying what you should have known before reading it. It says you should have basic knowledge in Perl and in HTML or XHTML. The reason for having basic knowledge in HTML is because Perl is normally used for the web, and the code samples assume that you are using the web or a localhost.

Need for a Two-Dimensional Array
This paragraph in the tutorial, explains the need for 2D array. A similar reasoning can be extended to multidimensional array.

Indexing in Perl Two-Dimensional Array
A two dimensional array is like a table of data with rows and columns. Cells are at the intersection of rows and columns and each cell takes a datum (singular for data). The rows are counted from top, beginning from zero. The columns are also counted from left, beginning from zero. In other words, the rows are identified with positive integers and the columns are also identified with positive integers. Such numbering is called indexing. In this tutorial, this paragraph explains that in more detail.

Creating a Two-Dimensional Array
This paragraph in the tutorial, explains how to create a 2D array. Details in the tutorial!

Accessing an Array Element
This paragraph gives you the rule of accessing a 2D array using indices. Details in the tutorial!

Placing Elements into a 2D Array One-by-One
This section explains how to feed a 2D array with data, one-by-one; that is, one datum after another. Details in the Tutorial!

Reading Values from a 2D Array One-by-One
This section explains how to read or get the values from a 2D array, one-by-one. You can read (program reading) a value and assign to a variable. Details in the tutorial!

Placing Elements into a 2D Array Row-by-Row
This section explains how to feed a 2D array with data, row-by-row; that is, one complete row of data after another. The question of reading values from an array, row-by-row, was not addressed as this would make the study unnecessary complicated for the novice, or someone who wants to quickly understand and start coding. Most of the time, as a coder, you do not need the complicated issues in 2D array. However, the question of reading data from a 2D array as a junk is addressed in this section of the tutorial.

Irregular Nature of a 2D Array
The Perl 2D array can have an irregular nature. This is something that is not in the C++ 2D array. That of Perl is explained in simple terms, in the tutorial.

Basic Characteristics of an Array
Are the above headings not the basics you need to know of an array, in order to do most of your array work? The answer is, Yes. So, as you can see, the tutorial brings down the study of a Perl 2D array into a set of simple rules. If you consider the above headings as questions, then in the tutorial, the questions are simply answered. The tutorial is short, just a one-part tutorial.

If you have basic knowledge in Perl and HTML, then go ahead and click the following link to read the tutorial.



About Author

Leave A Reply