eWebProgrammer
Distributednetworks GofPatterns
prev next prev next
  Course navigation
 
Lesson 8
Objective
Accessing array members
Array subscript allows access to array elements
   
As we learned in the previous lessons, an array is simply a list of scalars. The list can contain any scalars and has a definite order.
To access a particular element of an array, you can use the array subscript syntax like this:
@characters = ("dave", "frank", "hal");
print "$characters[0]\n";
Diagram of an array
Perl Subscript
The subscript, sometimes also called the index, is the number in the brackets ([0]).
The first member of the array ("dave") is element number zero. You will also notice that the $ is used to access the array, because the member of the array is a scalar.

In the next lesson, subscripts will be examined in more detail.
  Course navigation