Introduction
A hash is a two-dimensional array which contains keys and values, they’re sometimes called “associative arrays”, or “lookup tables”. Instead of looking up items in a hash by an array index, you can look up values by their keys.
Entire hashes are denoted by ’%’:
%days # (key1, val1, key2, val2 …)
A Hash represents a set of key/value pairs.
my %fruit color = (“apple”, “red”, “banana”, “yellow”).
You can use whitespace and the “=>” operator to lay them out more nicely:
my %fruit_color = (
apple => “red”,
banana => “yellow”,
);
To get at hash elements:
$fruit_color{“apple”}; # gives “red”
You can get at lists of keys and values with “keys()” and “values()”.
my @fruits = keys %fruit_colors;
my @colors = values %fruit_colors;
$days{‘Feb’} # the ‘Feb’ value from hash %days
accessing the HASH Element
To access the hash element use the syntax like: ”’$hash{$some_key}”’ This is similar to what we used for array but here we used curly braces {} instead of square brackets. []