Perl
  Home arrow Perl arrow Page 4 - Perl Lists: The Split() Function
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 Rational Software Development Conference
 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 Lists: The Split() Function
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-04-07

    Table of Contents:
  • Perl Lists: The Split() Function
  • Using Split() On a String
  • Limiting the Amount of Splits
  • Assigning a List to Another List

  • 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 Lists: The Split() Function - Assigning a List to Another List
    (Page 4 of 4 )

    This is a pretty simple thing to do. Say you have a list of your grades for the semester. As you take your tests and whatnot, you want to create a new list showing your grades up to a certain point. Here is how you would do so:


    #!/usr/bin/perl

    @FirstMonth=('A ','B ','A ','D ');

    @SecondMonth=('A ','B ','C ','A ',@FirstMonth);

    print @SecondMonth;

    This adds the values in @FirstMonth to the end of the @SecondMonth list, resulting in:

      A B C A A B A D

    We could continue this process as the months go on:


    #!/usr/bin/perl

    @FirstMonth=('A ','B ','A ','D ');

    @SecondMonth=('A ','B ','C ','A ',@FirstMonth);

    @ThirdMonth=('F ','F ','A ','A ',@SecondMonth);

    @FourthMonth=('A ','A ','A ','A ',@ThirdMonth);

    print @FourthMonth;

    You will note that I did not write @FourthMonth=('A','A','A','A',@FirstMonth,@SecondMonth,@ThirdMonth). This is because it would have been redundant and added even more fields. Remember that the @SecondMonth already contains all of @FirstMonth's value. And likewise, @ThirdMonth contains all of @FirstMonth and @SecondMonth's values. And so forth.

    The result of this code is:

      A A A A F F A A A B C A A B A D

    And while we are at it, we can also assign variables to the mix as well. Here it is in code:


    #!/usr/bin/perl

    @FirstMonth=('A ','B ','A ','D ');

    @SecondMonth=('A ','B ','C ','A ',@FirstMonth);

    @ThirdMonth=('F ','F ','A ','A ',@SecondMonth);

    @FourthMonth=('A ','A ','A ','A ',@ThirdMonth);

    $ExtraCredit="A";

    @Total=(@FourthMonth, $ExtraCredit);

    print @Total;

    The end result:

      A A A A F F A A A B C A A B A D A

    Looks like you had some extra-curricular activity in their a few times with those F's. Wink, wink.

    Well, that's all the time we have for this one. We still have a ways to go on Lists and Hashes, including Multi-Dimensional lists and the List::Util, but we're making progress. Be sure to join me next time as we continue, and hopefully one day, finish this discussion.

    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.

       · Welcome to another article in our series on Perl Lists and Hashes. In this episode...
     

       

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