Perl
  Home arrow Perl arrow Page 4 - Beginning Programming Perl(s)
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 
IBM Developerworks
 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

Beginning Programming Perl(s)
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2007-10-10

    Table of Contents:
  • Beginning Programming Perl(s)
  • Storing Data in A Variable
  • Quoth the Raven
  • List Data Types

  • 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Beginning Programming Perl(s) - List Data Types
    (Page 4 of 4 )

    Sometimes you store stuff in a folder in real life. Now imagine that you have 26 folders in a drawer alphabetized from A-Z. Since you are a programmer, those files probably contain the names and addresses of girls that have rejected you. If you are a young programmer, you are only using one drawer. If you are older, well...you've switched from drawers to outdoor storage sheds. Either way, that is an example of a List Data Type.

    Simply put, a List is a group of scalars put in order. There are a variety of ways to order the scalars, which we will get into later on. If you are familiar with arrays in other programming languages, you'll know that a List is the same thing.

    Here is how you store data in a List:


    @my_cats = {'Joni ', 'Chachi ', 'Richie ', 'Fonzie ', 'Potsy '};

    The above creates a list with five scalars in it. If we do the following code:


    #!/usr/local/bin/perl

    @my_cats = {'Joni ', 'Chachi ', 'Richie ', 'Fonzie ', 'Potsy '};

    print @my_cats;

    This would print the following:


      Joni Chachi Richie Fonzie Potsy

    I can store numbers in Lists also, or mix numbers and characters if I choose. Perl doesn't care. It's too busy unwrapping that Hershey bar (the one with almonds).

    As you can see, Lists must have the @ symbol as the first part of their name. They use the lowercase naming convention (or at least I do) and it's best to separate words with underscores, though in truth you don't have to.

    So let's say a girl wants to use my cat program to see the names of all my cats. I'm clearly embarrassed to have so many (or I would be if I really did have that many). So I would create a program that would only show the name of one cat from my List.


    #!/usr/local/bin/perl

    @my_cats = {'Joni ', 'Chachi ', 'Richie ', 'Fonzie ', 'Potsy '};

    print $my_cats[1];

    This would print the name Chachi to the screen. I know what you are thinking and you can cool your biscuits right there (within arms reach...I'm hungry). Why didn't it print Joni? Simple. Lists start off at 0 and work their way up. To print Joni and Richie, you would use the following code:


    #!/usr/local/bin/perl

    @my_cats = {'Joni ', 'Chachi ', 'Richie ', 'Fonzie ', 'Potsy '};

    print $my_cats[0,2];

    You may have noticed in the above examples that I switched the @ symbol to the $ symbol on the last line. In addition to wanting to confuse you, this is also necessary because you are calling individual portions of the item (scalars) and not the entire item itself.

    You will note that the sample rules apply for quotes when working with arrays. If I wanted a list of contractions, I would do it this way


    #!/usr/local/bin/perl

    @my_contractions = {'Won't ', 'Can't ', 'Don't '};

    print @my_contractions;

    The above code prints:


      Won't Can't Don't

    Conclusion

    While we are not finished with data types or this series, I am finished with this current tutorial. In the next tutorial, we will wrap up Lists and move on to the third data type, and use operators to manipulate data.

    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.

       · This is the second article in a series on Perl. It delves into the different Data...
       · ...when I view the article in my browser, in the code, the backslashes...
     

       

    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 5 hosted by Hostway