Perl 6 Perl 6 Lists, Arrays, and Hashes vivified #16

List contexts

Perl 6 has several list interpolation contexts

Use "@" or ".list" to get the list form of an object

my @a = 1,2,3;
my @b = 10,20,30;
my $c = [ 100, 200, 300 ];

my @two = (@a, @b, $c);       # 1,2,3,10,20,30,[100, 200, 300]
say @two.elems;               # 7

my @thr = (@a, @b, $c.list);  # 1,2,3,10,20,30,100,200,300
say @thr.elems;               # 9

for   $c  { print "loop", $_ }    # "loop100 200 300"
for @($c) { print "loop", $_ }    # "loop100loop200loop300"
Copyright © 2011
http://www.pmichaud.com/2011/pres/