And the benchmark:

use strict; use warnings; use Benchmark qw(cmpthese); my $rec = ['xyz10', 'abc0', 'axy1', 'xab02']; my ($ok, $no) = OP ($rec); print "OP:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; ($ok, $no) = GF ($rec); print "\nGF:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; ($ok, $no) = Fletch ($rec); print "\nFletch:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; ($ok, $no) = JDPorter ($rec); print "\nJDPorter:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; ($ok, $no) = Tanktalus ($rec); print "\nTanktalus:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; ($ok, $no) = Roy ($rec); print "\nRoy:\n " . join ", ", @$ok; print "\n " . join ", ", @$no; print "\n\n"; cmpthese ( -1, { 'OP' => sub {OP ($rec)}, 'GF' => sub {GF ($rec)}, 'Fletch' => sub {Fletch ($rec)}, 'JDPorter' => sub {JDPorter ($rec)}, 'Tanktalus' => sub {Tanktalus ($rec)}, 'Roy' => sub {Roy ($rec)}, } ); sub OP { my $rec = shift; my @ok = grep { $_ =~ m/[0-9][0-9]$/ }@$rec; my @no = grep { $_ !~ m/[0-9][0-9]$/ }@$rec; return (\@ok, \@no); } sub GF { my $rec = shift; my (@ok, @no); map {/[0-9][0-9]$/ ? push @ok, $_ : push @no, $_} @$rec; return (\@ok, \@no); } sub Fletch { my $rec = shift; my (@ok, @no); push @{/\d{2}$/ ? \@ok : \@no}, $_ for @{$rec}; return (\@ok, \@no); } sub JDpart (&$@) { my $condition = shift; my $receivers_ar = shift; push @{ $receivers_ar->[ &$condition ] }, $_ for @_; @$receivers_ar } sub JDPorter { my $rec = shift; my (@ok, @no); JDpart {/[0-9][0-9]$/ ? 0 : 1 } [\@ok, \@no], @$rec; return (\@ok, \@no); } sub Tpart (&@) { my ($condition, @array) = @_; my (@true, @false); foreach (@array) { if ( $condition->() ) { push @true, $_; } else { push @false, $_; } } return \@true, \@false; } sub Tanktalus { my $rec = shift; my ($ok, $no) = Tpart {m/[0-9]{2}$/} @$rec; return ($ok, $no); } sub Roy { my @no; my @ok = grep {/[0-9][0-9]$/ or !push(@no, $_) }@{$rec}; return (\@ok, \@no); }

Prints:

OP: xyz10, xab02 abc0, axy1 GF: xyz10, xab02 abc0, axy1 Fletch: xyz10, xab02 abc0, axy1 JDPorter: xyz10, xab02 abc0, axy1 Tanktalus: xyz10, xab02 abc0, axy1 Roy: xyz10, xab02 abc0, axy1
Rate Tanktalus OP JDPorter Roy Fletch + GF Tanktalus 39861/s -- -14% -23% -43% -44% + -57% OP 46391/s 16% -- -11% -34% -35% + -50% JDPorter 51919/s 30% 12% -- -26% -27% + -44% Roy 70510/s 77% 52% 36% -- -1% + -23% Fletch 71157/s 79% 53% 37% 1% -- + -23% GF 91995/s 131% 98% 77% 30% 29% + --

Update: forgot Roy Johnston's version


Perl is Huffman encoded by design.

In reply to Re: Splitting array into two with a regex by GrandFather
in thread Splitting array into two with a regex by jredburn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.