This section describes what is a list value constructor, a list of scalar values separated by commas. Elements of a list value can be accessed with the subscription notation [i].
List value constructors are used to construct list values.
A list value represents an ordered list of scalar values indexed by
numbers starting with 0.
A list value constructor must follow these rules:
A list value constructor is a list of individual scalar values separated by commas.
For example, 'hello' and 3,5,7,11.
You should use parentheses to protect a list value constructor as a single unit to avoid confusions.
For example, ('hello') and (3,5,7,11).
If you do use parentheses, then you don't have to put string literals in quotes.
For example, (hello) and (Mon,Tue,Wed).
Here are some good and bad examples of list value constructors:
'hello'; # ok, a single scalar is also a list
3,5,7,11; # ok
'Mon','Tue','Wed'; # ok
('Mon','Tue','Wed'); # ok
(Mon,Tue,Wed); # ok
'Mon',2,'Apple'; # ok
'Jan',31,'Feb',28,'Mar',31; # ok
'Jan' 'Feb' 'Mar'; # bad, need commas to separate the elements
Jan, Feb, Mar; # bad, need quotes
An element in a list value can be accessed by the subscription notation, [index].
In this case, you need to use parentheses to protect the list value.
Also note that negative index can be used to count down from the last entry.
If the index is out of the range, you are accessing a undefined scalar.
Here is a sample Perl script with list subscriptions: