next up previous contents index
Next: Hashes Up: Perl data structures Previous: Scalar Values

Arrays or Lists

   Arraysgif have been implemented in a really efficient way and play a very important role in  perl . A lot of important functions return arrays. For instance, in line 12 of the introducing example, the keys instruction returns a list of all users. It is then taken by the sort function which again returns a list of all users which is sorted now.

A list of scalars is constructed by a set of scalar values which are separated by commas and enclosed in parentheses. For example, the following statement assigns a list of two elements to the variable greetings:

@greetings = ("hello", "world");

The most important instruction when working with arrays is the foreach statement. It is a kind of a for loop which is processed once for each element of the list. The appropriate element is assigned to the loop variable or to $_ if no loop variable is given.



Ingo Melzer
Mon Aug 5 15:12:01 MET DST 1996