Perl
  Home arrow Perl arrow Page 2 - Perl: Bon Voyage Lists and Hashes
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: Bon Voyage Lists and Hashes
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2008-08-12


    Table of Contents:
  • Perl: Bon Voyage Lists and Hashes
  • Adding and Removing Values
  • Push
  • Making Hashes Out of Lists

  • 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: Bon Voyage Lists and Hashes - Adding and Removing Values
    ( Page 2 of 4 )

    In our last article we learned to add rows and columns to a two-dimensional list. We are going to continue this discussion, briefly, by showing you how to use some functions to accomplish the same goals.

    You may remember from our conversation about normal lists that there are several functions available to add and remove items. Namely they are pop, push, shift, and unshift. They work pretty similar with two-dimensional lists, but with some minor changes. Don't worry; I won't eat up a lot of time showing how to use these functions here, as that would mostly be repetitive. Still, the changes are important to note.

    Unshift

    As you may recall, unshift() adds an element to the leftmost position, or beginning of a list. It does the same thing in two-dimensional lists. The only difference is the code:


    #!/usr/bin/perl

    @Bookshelf = (

    [" # ", " Author ", " Title ", " Genre ", " Rating ", " Location "],

    [' 1 ', ' Stephen King ', ' It ', ' Horror ', ' 5 ', ' Top '],

    [' 2 ', ' Clive Barker ', ' Imajica ', ' Horror ', ' 5 ', ' Top '],

    [' 3 ', ' Neil Gaiman ', ' American Gods ', ' Dark Fantasy ', ' 5 ',

    ' Top '],

    [' 4 ', ' Dean Koontz ', ' Tick-Tock ', ' Horror ', ' 1 ', '

    GarbageCan '],

    [' 5 ', ' Charles Bukowski ', ' Letters from a Dirty Old Man ', '

    Literature ', ' 5 ', ' Top '],

    [' 6 ', ' Chuck Pahluniak ', ' Fight Club ', ' Dark Fantasy ', ' 5 ',

    ' Middle ']

    );

    unshift(@Bookshelf, [' 1 ', ' T.H. White ', ' The Once and Future King

    ','Fantasy ', ' 5 ', ' Middle ']);

    print @{@Bookshelf[0]};

    When you run this code, it prints out the new record in row 0:

      1 T.H. White The Once and Future King Fantasy 5 Middle

    You will note that the record that previously held the 0 row position is now moved to row 1, and row 1 is now row 2, and so forth. This of course messes up our use of row 0 as a header with all of the column names, but we can fix that later.



     
     
    >>> 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