Camelia
Prev: Perl 6 Lists and Arrays

List Literals, list ranges

Things in () separated by commas are called a list of things. Actually you don't even need the parentheses for the list, it just clarifies precedence. A list is an ordered set of scalar values. Examples of lists:

examples/arrays/list_literals.p6
#!/usr/bin/env perl6
use v6;

(1, 5.2, "apple");          # 3 values

(1,2,3,4,5,6,7,8,9,10);     # nice but we are too lazy, so we write this:
(1..10);                    # same as (1,2,3,4,5,6,7,8,9,10)
(1..Inf);                   # represents the list of all the numbers
(1..*);                     # this too

("apple", "banana", "peach", "blueberry");   # is the same as
<apple banana peach blueberry>;              # quote word

my ($x, $y, $z);               # We can also use scalar variables as elements of a list

We actually don't even need the parentheses in most of the cases.

Prev: Perl 6 Lists and Arrays

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: