Hash Manipulation

Hash arrays are different from regular arrays. A hash array is an associative array. Where a normal array is an indexed list, with each item referred to by its index number, a hash is a list of value pairs. A value pair is where the first item (key) refers to the second item (value); when the first item is referred to, the second item is the value returned. This can be easily illustrated with the following small hash array for the days of the week:

%day_of_the_week =
( 0, Sunday, 1, Monday, 2, Tuesday, 3, Wednesday, 4, Thursday, 5, Friday, 6, Saturday);

The hash can also be defined this way:

%day_of_the_week= ( 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', ); ...

Get Practical UNIX 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.