1. the hash key is unique and the value can be repeated!
2. Access the hash Element
$ Hashname {"$ key"}; # hash is braces, array is square brackets, and key is string
$ Family_name {"Fred"} = "firstd"; # assign a value to the hash Element
3. the hash key supports any expression.
$ Foo = "Na ";
$ Family_name {$ Foo. "Me"}; # obtain the value of $ family_name {"name "}.
4. Access the entire hash
% Family_name
5. Hash and list Conversion
% Some_hash = {"peison1", 35, "person2", 43, "person3", 56}; convert the list to a hash
@ Arry = % some_hash; Convert hash to list
6. Hash sorts key-value pairs again, and the output and input order may be different.
7. Hash replication and Inversion
% New_hash = % old_hash; first convert old_hash to list, then convert the list to new_hash
% In_hash = reverse % old_hash; key-value swaps are generally performed only when the hash value is unique. Otherwise, the later values of the same key will overwrite the original values.
8. Fat arrows
As another method of writing comma, it is easy to distinguish key-value pairs
% My_hash = (
"Fred" => "fsas ",
"Fdsred" => "fsdsas ",
"Frsdesdd" => "fdssas ",
)
The end of the comma cannot be omitted, and parentheses are used on both sides.
9. Get the key value
@ Key = keys % hash; # Return key list
@ Value = values % hash; # Return Value List, consistent with the key order
$ Num = keys % hash; # Number of Return key-value pairs
10. List hash key-value pairs
While ($ key, $ value) = each % hash) {print "$ key => $ value \ n" ;}# the returned result of each is a list, the result of boolean evaluation in while is the number of elements in the list (2)
11. Common Hash Functions
Exists $ hash {"DSA"}; # determines whether a DSA key exists.
Delete $ hash {"DSA"}; # No error is returned regardless of whether the specified key exists or not. It is different from assigning a value to UNDEF.
12. You can insert a single hash value into a double quotation mark string. "hash value is $ hash {$ person}" does not support interpolation of the entire hash.
13. Get environment variable configuration and other information
You can access % env to obtain the PATH value, for example, print "path is $ ENV {path }".
Get the environment variable set outside the program: $ ENV {character}