This section describes how a hash variable can be assigned with a list value. Hash elements are referred by key subscription notation as scalar expressions, like $identifier{'key'}. An unassigned hash variable contains the (undef) value.
Hash variables can be used in a Perl script under these rules:
An hash variable should be assigned with a list value constructor using an assignment operation.
Every 2 elements in the list value will be formed into a pair of key and value into the hash variable.
If there is an extra key at the end of the list without a value, this key will have no value assigned.
For example: %siteRanks = ("herongyang.com", 4, "perl.org", 6, "google.com", 9).
To increase legibility, the => operator can be used to link a value to the key in the list value constructor.
For example: %siteRanks = ("herongyang.com" => 4, "perl.org" => 6, "google.com" => 9).
Each value in a hash variable can be referenced by a scalar expression with the key subscription notation,
$identifier{"key"}. The "key" is the string value of the key linked to the value in the hash.
For example: $siteRanks{"herongyang.com"} is a scalar expression referring to the value linked
to the key "herongyang.com" in the hash variable.
If a new value is assigned to a new key in the hash variable, a new pair of key and value
will be added into the hash variable.
If you are trying to access a value with a key that has no value assigned, you will get the undef value.
Here are some examples of hash variable assignment operations with list value constructors: