Over the course of this tutorial, I'll be examining Perl's arrays in detail, explaining what they are, how they work, and how you can use them to get things done faster, better and cheaper. In addition to providing a gentle introduction to Perl arrays and hashes in general, this article will also offer you a broad overview of Perl's array manipulation functions, providing you with a handy reference that should help you write more efficient code.
Perl also allows you to replace indices with user-defined "keys", in order to create a slightly different type of array, called a "hash" or "associative array". Each key is unique, and corresponds to a single value within the array.
In this case, %dinner is an associative array variable containing key-value pairs. The % symbol before the variable name indicates that it is an associative array, while the => symbol is used to indicate the association between a key and its value.
Now, in order to access the value "fried squid rings", I would use the key "starter" and the notation $dinner{"starter"}, while the value "chocolate cake" would be accessible via $dinner{"dessert"}. Here's an example:
Note that when using an associative array, Perl usually re-sorts the key-value pairs such that they are optimized for retrieval. Therefore, it's not a good idea to rely on your original element positions when accessing values in a hash; instead hash values should always be accessed by their respective keys.