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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PERL

Perl: Dimensional Lists
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek