Hashes

A hash is a set of key/value pairs. Hashes are preceded by a percent sign (%). To refer to a single element of a hash, you use the hash variable name followed by the “key” associated with the value in braces. For example, the hash:

%fruit = ('apples', 3, 'oranges', 6);

has two values (in key/value pairs). If you want to get the value associated with the key apples, you use $fruit{'apples'}.

It is often more readable to use the => operator in defining key/value pairs. The => operator is similar to a comma, but it’s more visually distinctive and quotes any bare identifiers to the left of it:

%fruit = (
    apples  => 3,
    oranges => 6
);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.224.193