in reply to how to seperate array after a certain number of elements?
That assumes the list has at least 5 elements and is exactly divisible by 5. Otherwise:my @myMainArray = map { [ $myArray[$_] .. $myArray[$_+4] ] } grep { !($_ % 5) } 0 .. $#myArray;
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 |