Home arrow Perl Programming arrow Perl Hashes

Perl Hashes

Thanks for stopping by for this seventh part in the series on Perl Lists and Hashes. Here we will discuss working with a new way to store data known as a Hash. We'll cover the basics, such as how to create them, and how to locate data within them. You'll learn to add records, remove records, and much more. If there is time, we will also cover multidimensional lists.

TABLE OF CONTENTS:
  1. Perl Hashes
  2. Creating A Hash
  3. Printing from a Hash
  4. Printing All the Values or Keys in a Hash
  5. Alternative Methods for Creating Hashes
By: James Payne
Rating: starstarstarstarstar / 6
April 28, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In our previous article we covered the remaining List::Util subroutines. We used min(list) to find the minimum numeric value in a list. We also worked with its brother, the minstr(list), which as you will recall found the smallest string value in a list. We learned that uppercase letters hold a lower value, surprisingly, then lowercase ones. We also learned to use shuffle to randomly sort our lists, and sum(list) to sum up the numeric values in our lists.

Hash...Not What It Sounds Like

If you have worked with Access or Excel, or any grid-type program, you are familiar with the concept of a hash. These aren't exactly like a hash mind you, but a similar idea. Whereas with a typical list, you refer to the values stored in them by referencing their element or index number, like so:

  array[0]

with hashes you look them up with their key. When you create an element in a hash, you assign it a key value. That key, plus the value, creates a record. If that is still confusing to you, never fear: after our example it should be crystal clear.



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