Yet another way to do this (which outperforms the above responses by my esteemed monk colleagues by at least 50% when output is ignored):
for (my $i = 1; $i < $#a; $i += $n) { say $a[$i] }That said, loop performance will be obliterated by the I/O of say() (or print()), so if the C-like for loop construct doesn't look Perlish enough for your tastes, absolutely go with one of the other approaches, especially if your array is small.
In reply to Re: print every nth element of an array.
by rjt
in thread print every nth element of an array.
by rinaldi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |