Filling Your Hash

Individual hash elements are created by assigning values to them, much as with array elements. For example, you can create individual hash elements, as in the following:

$Authors{'Dune'}='Frank Herbert';

In this example, you assign to an element in the hash %Authors. The key for this element is the word Dune, and the data is the name Frank Herbert. This assignment creates a relationship in the hash between Dune and Frank Herbert. THe value associated with the key, $Authors{'Dune'}, can be treated like any other scalar; it can be passed to functions, modified by operators, printed, or reassigned. When you're changing a hash element, always remember that you're modifying the value stored in the hash element, not the hash itself. ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.