Prev: Perl 6 Lists and Arrays

List Literals, list ranges

Note! This site is about Perl 6.
If you are looking for a solution for Perl 5, please check out the Perl 5 tutorial.

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:


#!/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.

The Perl 6 Tricks and Treats newsletter has been around for a while. If you are interested to get special notification when there is new content on this site, it is the best way to keep track:
Full name:
This is a newsletter temporarily running on my personal site ( using Mailman, till I implement an alternative system in Perl 6.
Gabor Szabo
Written by Gabor Szabo

Published on 2012-01-01

Prev: Perl 6 Lists and Arrays


In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus
Suggest a change
Elapsed time: 2.2526978

Perl 6 Tricks and Treats newsletter

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