Table of Contents

Elements of Arrays

Arrays are not much use unless we can get to individual elements. Firstly, we are dealing with a single element of the list, so we cannot use @ which refers to multiple elements of the array. It is a single, scalar variable, so $ is used. Secondly, we must specify which element we want. That's easy - $array[0] for the first, $array[1] for the second and so forth. Array indexes start at 0, unless you do something which is so highly deprecated ('deprecated' means allowed, usually for backwards compatibility, but disapproved of because there are better ways) I'm not even going to mention it.

Finally, we force what is normally list context (more than one element) into scalar context (single element) to give us the amount of elements in the array. Without the scalar , it would be the same as the second line of the program.