Perl
  Home arrow Perl arrow Perl: Sailing the List(less) Seas
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: Sailing the List(less) Seas
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-17

    Table of Contents:
  • Perl: Sailing the List(less) Seas
  • Printing Specific Elements
  • Slices
  • Replacing an Element Using a Slice OR Slice and Dice

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Perl: Sailing the List(less) Seas
    (Page 1 of 4 )

    People love lists. Everywhere you look you see them. On magazines, on television. They're everywhere; you can't escape. In this article and the ones that follow, I am going to teach you to blend in with the crowd by using Perl to create lists, multidimensional lists, and hashes, and furthermore, I'll show you how to manipulate each of them.

    I know what you are thinking: haven't we talked about this subject before? Yes, yes we did. But only briefly, way back when I went over the various data types in Perl. Here, we will look at them much more closely. So put on your trifocals and get out your bullets, because its time to make us some lists.

    Lists: Just a Fancy Way of Saying Array

    If you remember the basics of lists, or just can't wait to get to the end of this article, feel free to skip ahead. If you need a refresher in what lists are, then stay tuned.

    A list is simply a group of items or elements that are in order. If you know about arrays, then this should seem familiar, as lists are just arrays. If you aren't, then think of a list as a group of variables. Each variable resides within the list and has an index number. The values within the list can be numbers or strings, or numbers and strings. Below is a sample showing how to store data in a list and print out the values:


    #!/usr/bin/perl

    @gladiators=('Nitro ', 'Blaze ', 'CountFistula ', 'TheNutcracker ');

    print "These gladiators will mess you up: ";

    print @gladiators;

    The above code prints out:

      These gladiators will mess you up: Nitro Blaze CountFistula TheNutcracker

    Pretty simple right? You will note a few things about the above code; first, unlike scalar variables, you start the variable name with an @ symbol when dealing with lists, instead of the $ symbol. Each element in the list is encased in a quotation mark, and separated from the other elements in the array by a comma. I also added a space at the end of each element. Had I not, the words would have all printed together.

    To print the list, I simply typed print followed by the name of the array. But what if I wanted to print out only certain values in the list? That is covered in the next section

    More Perl Articles
    More By James Payne


       · Thank you for stopping by to read my article on Perl Lists. In this article we...
     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway