in reply to Read Every n elements from Array

well splice is destructive, you could alternatively use array slices:

print @arr[$idx..$idx+2]; $idx+=3;

or

print @arr[$idx++,$idx++,$idx++];

Cheers Rolf

Replies are listed 'Best First'.
Re^2: Read Every n elements from Array
by ikegami (Patriarch) on Feb 17, 2011 at 22:38 UTC

    In general, reading and writing to a variable in the same statement can lead to problems. It's not a problem here, but that's not obvious at a glance. For example, that code has undefined behaviour in C. My compiler happens to get it "wrong":

    $ cat a.c #include <stdio.h> int main() { int i = 0; printf("%d %d %d\n", i++, i++, i++); return 0; } $ gcc -Wall -o a a.c && a a.c: In function ‘main’: a.c:5: warning: operation on ‘i’ may be undefined a.c:5: warning: operation on ‘i’ may be undefined 2 1 0

    It's simpler just to avoid the issue.