Perl
  Home arrow Perl arrow Perl: Sailing the List(less) Seas
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: Sailing the List(less) Seas
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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: 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
     

       

    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