Perl
  Home arrow Perl arrow Page 2 - Perl Lists: More on Manipulation
CIO Insight
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 on Manipulation
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2008-03-24

    Table of Contents:
  • Perl Lists: More on Manipulation
  • Pop() Goes Your Data
  • Unshift My Heart
  • Splice...It Sounds Like a New Citrus Soda, But It's Not

  • 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 on Manipulation - Pop() Goes Your Data
    (Page 2 of 4 )

    What else is there to say about the pop() function? Nothing, that's what. Here is the code:


    #!/usr/bin/perl

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

    @new=('Max Fightmaster ');

    push(@gladiators, @new);

    print @gladiators;

    print "\n\n";

    $deleted=pop(@gladiators);

    print @gladiators;

    print "\n\n";

    print $deleted;

    This code again creates the two lists and adds the values to them, then uses push() to add the data from @new to @gladiators. We print out the value of @gladiators to show it worked, and then create a new variable named $deleted, using the pop() function to remove the last element in the @gladiators array and store it in $deleted. Finally, we print out the values of both the @gladiator list, and the $deleted variable, resulting in (takes a deep breath):

      Nitro Blaze CountFistula TheNutcracker Glutious-Minimus Max Fightmaster

      Nitro Blaze CountFistula TheNutcracker Glutious-Minimus

      Max Fightmaster

    You will note that when we remove data from a list in this manner it gets stored in a variable, not a list. Likewise, you cannot, with this method, deduct data from a list using another list; again, this is because you are simply removing the end element, and not "elements."

    More Perl Articles
    More By James Payne


       · Thanks for stopping by to read another installment on my series about Perl Lists and...
     

       

    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




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