Computer Science: what is an array?

Returning to computer science, we continue our summer tutoring project surrounding PERL programming.  The tutor introduces the concept of an array – first, from a generic viewpoint.

Every computer programming language I know of uses the concept of an array. Python, if I recall correctly, uses the term list. Although a given computer language has its own flavour of it, the array is useful to preview from a generic point of view.

Here’s an example of an array: (“eggs”,”bread”,”milk”,”butter”,”jam”). This array contains five pieces of information. You could also say it contains five items. However, computer science people would commonly say it contains five values. Note that a value doesn’t have to be a number; it can also be a noun.

One curiosity of arrays is that they start at 0: in the array above, element 0 is “eggs”. Element 1 is “bread”. Therefore, “jam” is element 4, even though it’s in the fifth position.

Perl has functions that remove or add values to an array, give its length, etc. In Perl, the array above might be defined as follows:


The @ symbol means it’s an array. $groceries[0] is the zeroth element of @groceries, so $groceries[0] is “eggs”. $groceries[3] is “butter”.

For more about arrays, as well as programming in general, please return soon. Hope you’re enjoying the season, wherever you are. Here, the heat wave continues:)

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply