Perl
  Home arrow Perl arrow Page 2 - Perl Lists: More on Manipulation
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 Lists: More on Manipulation
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    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:
      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 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
     

       

    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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek