Perl
  Home arrow Perl arrow Perl: Dimensional Lists
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl: Dimensional Lists
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-19

    Table of Contents:
  • Perl: Dimensional Lists
  • Printing From Two-Dimensional Lists
  • Printing an Entire Row from a Two-Dimensional List
  • Using Two-Dimensional Lists to Create Variables and Lists

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Perl: Dimensional Lists


    (Page 1 of 4 )

    Thanks for stopping by to read my tenth installment on working with hashes and lists in Perl. In our previous article we learned how to find out if a hash holds a specific value, does not hold a specific value, or holds any value whatsoever. We further learned to create our first two-dimensional array and then worked to better understand how exactly a two-dimensional array works. Which is where we pick up in this article.

    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).

    More Perl Articles
    More By James Payne


       · Thanks for stopping by for another article. In addition to completing our...
     

       

    PERL ARTICLES

    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl
    - Perl: More on Lists and Hashes
    - Perl: Dimensional Lists
    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT