Perl
  Home arrow Perl arrow Page 2 - Perl Lists: More Functions and Operato...
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 Lists: More Functions and Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-31

    Table of Contents:
  • Perl Lists: More Functions and Operators
  • Removing Elements without Storing Them
  • Using Splice() to Add and Replace
  • Adding Values to a List with Splice()
  • A Few Operators

  • 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    Perl Lists: More Functions and Operators - Removing Elements without Storing Them
    (Page 2 of 5 )

    You might not wish to store the elements you removed while using splice(). It takes up memory, and can equate to more code and variables floating around than you really want. Here is how you remove elements without storing them:


    #!/usr/bin/perl

    @KoolAidFlavors = (@KoolAidFlavors, 'Grape ','Cherry ','Watermelon

    ','Fruit-Punch ','Orange ');

    print @KoolAidFlavors;

    print "\n\n";

    splice(@KoolAidFlavors, 1,2);

    print @KoolAidFlavors;

    print "\n\n";

    Here we create the @KoolAidFlavors list and add values to it. Next we print out the list, then use splice() to remove the two elements that follow the first element. Finally we print @KoolAidFlavors again, showing that we extracted some data from it. Here is the result:

      Grape Cherry Watermelon Fruit-Punch Orange

      Grape Fruit-Punch Orange

    You can also remove items using a null list:


    #!/usr/bin/perl

    @KoolAidFlavors = (@KoolAidFlavors, 'Grape ','Cherry ','Watermelon

    ','Fruit-Punch ','Orange ');

    print @KoolAidFlavors;

    print "\n\n";

    splice(@KoolAidFlavors, 1,2,());

    print @KoolAidFlavors;

    print "\n\n";

    Which gives us the same result as above.

    More Perl Articles
    More By James Payne


       · Thanks for stopping by for another article in our series on Perl Lists and Hashes....
     

       

    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