Perl List

List

A list is a sequence of scalar values enclosed in parentheses. The following is a simple example of a list:

(1, 5.3, “hello”, 2)

This list contains four elements, each of which is a scalar value: the numbers 1 and 5.3, the string hello, and the number 2.

Lists can be as long as needed, and they can contain any scalar value. A list can have no elements at all, as follows:

()

This list also is called an empty list.

NOTE

A list with one element and a scalar value are different entities. For example, the list

(43.2)

and the scalar value

43.2

are not the same thing. This is not a limitation because one can be converted to or assigned to the other.

Previous Post

Next Post

Comments are closed.