Perl
  Home arrow Perl arrow Page 4 - 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 - Using Two-Dimensional Lists to Create Variables and Lists


    (Page 4 of 4 )

    Sometimes it is necessary to create an array from a value in a two-dimensional array. Maybe we want to see the secret lair of Man-Girl. Here is how we could do so:


    #!/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";

    $Lair=$StuporHeroes[0][0];

    print $Lair;

    This code takes the value located in the first row and first column of @Stuporheroes, and stores it in $Lair. We then print out the value, giving us:

      Mount Tittikinaka

    I could also store a complete row in a list like so:


    #!/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";

    @First = @{@StuporHeroes[0]};

    print @First;

    Just as in our earlier example of how to print an entire row, we specify which row to store in the variable in between the square brackets[]. In the above example, the result is:

      Mount Tittikinaka Man-Girl Is a good listener Has Man-Boobs

    To see how that two-dimensional list gets stored in a normal list, let's try this code:


    #!/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";

    @First = @{@StuporHeroes[0]};

    print @First[0];

    Here we print the first element in the @First list, which we made from the first row of @StuporHeroes. Here is the result:

      Mount Tittikinaka

    For a better example, let's print out each element in the list:


    #!/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";

    @First = @{@StuporHeroes[0]};

    print @First[0] . "\n";

    print @First[1] . "\n";

    print @First[2] . "\n";

    print @First[3] . "\n";

    The result:

      Mount Tittikinaka

      Man-Girl

      Is a good listener

      Has Man-Boobs

    And lastly, we can store the values in a hash as well:


    #!/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";

    %First = @{@StuporHeroes[0]};

    print %First;

    Returning the same result as above.

    Well that is all the time we have for this episode. We didn't get to all the topics we wanted to cover, but never fear; there are more articles to come. So be sure to check back often.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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