in reply to how to seperate array after a certain number of elements?

Also non-destructively:
my @myMainArray = map { [ $myArray[$_] .. $myArray[$_+4] ] } grep { !($_ % 5) } 0 .. $#myArray;
That assumes the list has at least 5 elements and is exactly divisible by 5. Otherwise:
my @myMainArray = map { exists $myArray[ $_+4 ] ? [ $myArray[$_] .. $myArray[$_+4] ] : [ $myArray[$_] .. $myArray[-1] ] } grep { !($_ % 5) } 0 .. $#myArray;

Replies are listed 'Best First'.
Re^2: how to seperate array after a certain number of elements?
by Roy Johnson (Monsignor) on Sep 20, 2007 at 15:37 UTC
    That refactors nicely:
    my @myMainArray = map [ @myArray[$_ .. ($_+4 < $#myArray ? $_+4 : $#myArray)] ], map $_ * 5, 0 .. $#myArray/5;

    Caution: Contents may have been coded under pressure.