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, ... ?
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]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With