in reply to Re^3: Splitting array into two with a regex
in thread Splitting array into two with a regex

Nice. Note that Example 2 can be called as such:
my @r = partition { $_ % 3 } [], 0 .. 12;
and autovivification will create the sub-refs, though only for those elements that actually get assigned to. It's probably best to go ahead and specify the arrayrefs, but it could be a little cumbersome. It can be made simpler by a little tweak: the 2nd argument can be an arrayref or a number; if a number, partition creates that many sub-array(ref)s.
sub partition (&$@) { my $condition = shift; my $receivers_ar = shift; ref $receivers_ar or $receivers_ar = [ map [], 1..$receivers_ar ]; push @{ $receivers_ar->[ &$condition ] }, $_ for @_; @$receivers_ar } my @r = partition { $_ % 3 } 3, 0 .. 12;
Also note that the map cannot be replaced with ([]) x $receivers_ar because that will make three copies of the same ref.

Caution: Contents may have been coded under pressure.