Multiple components in an array slice - equivalent to perl5: @a[0..1,3]

Your question is a little confusing, but assuming you've just got typos or whatever, I'll try to guess what you are asking.

This makes a simple array:

> my @a = "a", "b', "c", "d";
[a b c d]

This makes an anonymous array of a Range from 0..1 and a 3:

> @[0..1,3];
[0..1 3]

If you want it to pull values out of the @a array, you have to refer to it:

> @a[0..1,3];
((a b) d)

pulls the bits you asked for from @a -- The first element is the 0..1 parts of @a, (a,b) -- (Not sure why you want to see c in here..)

That's the nested list -- the two bits you asked for include the list in the first field, and the value d you asked for in the second field.

If you want it flattened instead of nested, you can use .flat:

> @a[0..1,3].flat;
(a b d)

In Raku (formerly known as Perl 6), 0..1 results in a single item, which is a range. In Perl 5, 0..1 immediately expands into two numbers.

One of my most common mistakes in Raku is forgetting to flatten things. The upside is that in Raku, we basically get the equivalent of Perl 5 references for free, which eliminates a lot of messy referencing and dereferencing.

Tags:

Slice

Raku