Home arrow Perl Programming arrow Perl: Bon Voyage Lists and Hashes

Perl: Bon Voyage Lists and Hashes

Thanks for stopping by for our final article on Perl lists and hashes. This marks our twelfth issue on the subject (at least until we get to some more advanced techniques later on) and in it, we will look at a few of the functions for manipulating two-dimensional lists, how to create lists with more than two dimensions, and finally, how to make a hash full of lists, which is really quite a handy tool.

TABLE OF CONTENTS:
  1. Perl: Bon Voyage Lists and Hashes
  2. Adding and Removing Values
  3. Push
  4. Making Hashes Out of Lists
By: James Payne
Rating: starstarstarstarstar / 1
August 12, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In our previous article we created a “database” of a bookshelf with some books on it. We then learned how to add rows to it, add a single column, and automate a process to add columns to every row. Here, we will continue working with the @Bookshelf “database.” Just so you don't have to go seeking out our previous article, here is the list of fields:

  • Book Number

  • Author

  • Title

  • Genre

  • Number of Stars (how good the book was in a ranking of 1-5, with five being the best)

  • Which shelf on the bookshelf it is located

And the code to create the two-dimensional list:


#!/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 ']

);



 
 
>>> More Perl Programming Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: