The easiest way is to iterate your array and pass the values ββto either of the two arrays depending on the condition, as in the example below.
for (@array) { if ($_ % 2) {push @odd, $_} else {push @even, $_} }
If you want to change the original array:
for (my $i =0; $i < @array; ++$i) { if ($array[$i] % 2) { push @odd, splice (@array, $i--, 1); } }
Why didnβt you recommend List :: MoreUtils :: part?
This module may not exist on the target system, which is always annoying.
Also, on the system I ran tests, I found that List::MoreUtils::part was twice as slow as the first fragment in this post, although with different implementations of part this could be the other way around.
Filip RosΓ©en - refp
source share