On Data Types

Like all programming languages, Perl provides several built-in basic data types:

  1. Scalars: numbers, strings and references

  2. Arrays or lists

  3. Hashes

We have already been exposed to all of them in ChapterÊ1 and ChapterÊ2. Scalars are discussed at length in ChapterÊ2, and are hence, not re-discussed here, except for references that we present in Section 3.3.

A scalar is a single-component data structure whereas lists and hashes are multi-component. A multi-component data structure provides representational efficiency since related data can be stored, accessed, and processed compactly and efficiently, without resorting to a plethora of similar-sounding variable names. This increases a programs comprehensibility as well as its maintainability. Lists and hashes differ in the manner in which individual components of the data structure are accessed and stored. Accessing a multi-component data structures individual parts requires being able to specify an address or index such that the elements can be distinguished from one another and accessed immediately in constant time or more or less constant time. Whether it is the first element, or an element buried way back in the data structure should not cause a major difference in accessing time. Both lists and hashes are flat data structures, allowing only one level of inclusion. In the case of a list, the addressing or indexing is done using numeric addresses for the elements. A list is a sequential data structure and the addressing scheme uses non-negative integers starting from zero. A hashs indexes are arbitrary scalars. Hashes require complex mathematical computation so that elements are stored without fear of loss, and accessed efficiently. An interested reader can consult a book such as Introduction to Algorithms [CLR97] to understand how hashes are implemented.