Perl
  Home arrow Perl arrow Page 2 - 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 
Mobile Linux 
App Generation ROI 
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 - Printing From Two-Dimensional Lists


    (Page 2 of 4 )

    As you will recall from our discussion of lists, when you print elements within them you refer to them by their location within the list, or their element number. Printing from a two-dimensional list is not much different. Instead of printing from the lone element number, you reference both the row number and column number. It's easiest to understand if you see it in action:


    #!/usr/bin/perl

    @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']

    );

    print $StuporHeroes[0][0];

    Here we assign the values to our two-dimensional list, and then call one of them out by referring to its position on the grid. Can you guess what gets printed? Guess no more:

      Mount Tittikanaka

    This value is in the first row and first column (remember rows and columns begin at zero, just like list/array elements). For a better example, let's print out the rest of the individual values:


    #!/usr/bin/perl

    @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 ']

     

    );

    print "\n\n";

    print $StuporHeroes[0][0] . "\n\t";

    print $StuporHeroes[0][1] . "\n\t";

    print $StuporHeroes[0][2] . "\n\t";

    print $StuporHeroes[0][3] . "\n\n";

    print $StuporHeroes[1][0] . "\n\t";

    print $StuporHeroes[1][1] . "\n\t";

    print $StuporHeroes[1][2] . "\n\t";

    print $StuporHeroes[1][3];

    Before I show you the results, just note that I formatted the printing to give a better view of the elements:

      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

    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

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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