A hash is a collection of scalars, but each element can be named rather than numbered as it would be in a list. This makes it similar to a database table in many ways and leads to some truly remarkable capabilities.
This topic is presented on public courses
Perl Programming,
Perl bootcamp
Examples from our training material
| acl | Sample answer - web_c2, page 152 |
| bankout | initialising a hash |
| cbdemo | How sort callbacks work |
| env2 | ENV module to import variables as globals |
| envrep | use of %ENV |
| h1 | Setting up, adding to, changing a hash (associative array) |
| hash1.pl | setting up and using a hash |
| nip2 | set up and loop though a hash in various ways |
| nip3 | the danger of jumping out of an each loop |
| nip4 | Sorting the keys of a hash |
| niports | hash - manipulation |
| peeps.pl | Set up a hash of people |
| so2 | Sort using your own sort subroutine |
| so4 | sort using a more complex routine |
| so5 | sorting with a comparison block |
| sorter | Demonstration of default dort order |
| stdhash | keys must be unique - example illustrates the problem |
| stdhash3 | Hash keys must be unique - so make up a new keu |
| stdhash4 | Keys must be unique - design new keys, add accessor loops to find multiple keys |
| sthash2 | Keys must be unique - solution 1 - Append all possible values |
| ukports | fill and look up a hash |
| web_count | Sample answer - web access counter question 1 |
| webc2 | Sample answer - 2nd question |
Opentalk forum discussions related to this topic
Summation of file size according to usersorting the spread sheetSorting a list of hashesSorting DataRunning another app with a changed environmentRemoving duplicate lines with a regular expressionReformatting questionIs this a hash in an SQL insert statementAnother large text file examplesorting program for golf scores
Pictures
Everyone's concentrating on the exercise
Background information
Some modules are
available for download as a sample of our material or under an
Open Training Notes License for free download from
http://www.training-notes.co.uk.
Topics covered in this module
What is a hash?
Setting up a hash.
Keys and values.
Accessing a hash.
Processing every element.
Sorting.
cmp and operators.
Programming techniques for hashes.
Deleting hash elements.
Special hashes.
The environment.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 600 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.