YAP6 Operator: Repeat Operators

by Adriano Ferreira

Another article of the series "Yet Another Perl 6 Operator"


Perl 6 has two repeat operators: one for replicating a string/buffer and the other for replicating lists.


String repeat 'x' takes a string as the left argument and the number of times to replicate as the right argument.



$string x $count

my $s = 'a' x 3; # 'aaa'
my $empty = 'foo' x 0; # ''
my $n = 2; my $dots = '.' x ($n - 3); # '' because ($n-3)<1

1 Comments

rir
2008-01-21 11:54:02
Does this allow such as: my @randoms = (rand()) XX *;


Thanks.