Perl Programming Perl: Dimensional Lists |
In addition to completing our understanding of how two-dimensional arrays work, we will also learn how to print from them, add, replace, and delete from them, and discuss going beyond just the two dimensions. It is a lot to cover, so let's begin. For the sake of continuity I am going to briefly describe how Two-Dimensional arrays work again (so you don't have to seek out the other article if you need a refresher). If you remember how they work, or already know, then feel free to skip this section and move on to the next. For those of you interested, keep doing what you are doing; read on. Better Understanding the Two-Dimensional List The best way to think of a two-dimensional list is like an Excel sheet. I used that same analogy with hashes, but really it applies more to this storage device. For instance, in a spreadsheet you enter data into a grid, like the one shown below:
As you can see, the value Spiderman is located at row 3, column A. Batman is row 5, column A, Thanos is row 8, column B, and so forth. This is how Perl sees your record. In our sample code above for instance, we assigned our lists values like this: @StuporHeroes = ( [' Mount Tittikanaka ', ' Man-Girl ', ' Is a good listener ', ' Has Man-Boobs '], ['Trailer Park', 'Deaf Leapard', 'Has a super sonic guitar', 'Is deaf and has one arm making him unable to play his guitar']
); Our first row contains all of the following data: “Mount Tittikanaka,” “Man-Girl,” “Is a good listener” and “Has man boobs.” Note that with lists, element numbers start at 0. All of these elements have a row number of zero. However, their column numbers differ. If I wanted to call on “Mount Tittikanaka” for instance, I would search for the value in row 0, column 0. If I wanted “Man-Girl,” I would search in row 0, column 1, and so forth. The second row contains the values: “Trailer Park,” “Deaf Leapard,” “Has a super sonic guitar” and “Is deaf and has one arm making him unable to play his guitar.” If I wanted to refer to “Trailer Park” I would point to row 1, column 0. “Deaf Leopard” is located at row 1 and column 1. Always keep in mind that elements start at 0 (as do our rows and columns).
blog comments powered by Disqus |
|
|
|
|
|
|
|