If I have an array myarray
in Python, I can use the slice notation
myarray[0::2]
to select only the even-indexed elements. For
I'll do this in a two-step process: first generate the desired indices, and then use a slice operation to extract them:
@indices = map { $_ * 2 } (0 .. int($#array / 2));
my @extracted = @array[@indices];
Step-by-step, thats: