From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Hashes or associative arrays

Hashes or associative arrays - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Hashes or associative arrays

- [Voiceover] Hashes, sometimes called associative arrays, are very powerful and very common in Perl. Here's a working copy of hash.pl from Chapter four of the exercise files. A hash is a special kind of an array that associates keys and values. You'll notice that the hash variable is introduced with a % and it's defined using a bare word key. Of course you can put it in quotes if you need to include whitespace in it, but a bare word is allowed there, followed by an association symbol, which is two characters: an = and a > and then a value, which in this case is a string, but it can be any value, and then a comma. Each of these key value pairs are separated by commas, and it's all enclosed in parentheses. So if I save and run this, you see that we get these values. We have a while list here, a while loop, and it defines two variables and assigns them the value from the hash. This each operator is just getting each successive value from the hash. The hash itself is not stored in any…

Contents