The range expression extracts a specified subsequence from a list or string:
expression-1[expression-2..expression-3]
The three expressions are evaluated in order. Expression-1 must return a
list or string (the sequence) and the other two expressions must return
integers (the low and high indices, respectively); otherwise,
E_TYPE
is raised. The $
expression can be used in either or both
of expression-2 and expression-3 just as before, meaning the length
of the value of expression-1.
If the low index is greater than the high index, then the empty string or list
is returned, depending on whether the sequence is a string or a list.
Otherwise, both indices must be between 1 and the length of the sequence;
E_RANGE
is raised if they are not. A new list or string is returned
that contains just the elements of the sequence with indices between the low
and high bounds.
"foobar"[2..$] => "oobar" "foobar"[3..3] => "o" "foobar"[17..12] => "" {"one", "two", "three"}[$ - 1..$] => {"two", "three"} {"one", "two", "three"}[3..3] => {"three"} {"one", "two", "three"}[17..12] => {}
Go to the first, previous, next, last section, table of contents.