Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ^5 (caret + number) mean?

Tags:

raku

Using ^5, one can get the first five elements of an array:

my @foo = 10..20;
say @foo[^5].join(',');

10,11,12,13,14

What is ^5 actually? Indexing syntax, a shortcut for lists, ... ?

like image 217
Stefanus Avatar asked Mar 30 '18 19:03

Stefanus


1 Answers

The prefix ^ operator is the upto operator. It generates a Range from 0 upto N (exclusive)

See also prefix:<^>.

In the example it is used as a specification of an array slice, so it is equivalent to @foo[0,1,2,3,4].

like image 195
Hunter McMillen Avatar answered Nov 15 '22 01:11

Hunter McMillen