I'm interpreting the language of your question to mean read every third element, starting with the first one. That's one situation where a good old "c-style loop" comes in handy:
use strict; use warnings; use feature qw/say/; my @array = qw/0 1 2 3 4 5 6 7 8 9 10 11 12/; for ( my $idx = 0; $idx < @array; $idx += 3 ) { say $array[$idx]; }
perlsyn discusses the various loop types. Your splice method is destructive to the original array, and requires that a new array be set up to accommodate the elements you've selected. The method I demonstrated leaves the original array untouched. If you actually want a new array, you could set one up and push the elements into it within the loop.
Update: You may be asking to read three elements at a time, if I read the language of your question a different way. It's possible to read three elements at a time by just using offsets within the loop, and this would still be non-destructive to your original array.
Dave
In reply to Re: Read Every n elements from Array
by davido
in thread Read Every n elements from Array
by vetrivel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |