<?xml version="1.0" encoding="windows-1252"?>
<node id="1001758" title="Re: Array splitting" created="2012-10-31 18:50:09" updated="2012-10-31 18:50:09">
<type id="11">
note</type>
<author id="401112">
johngg</author>
<data>
<field name="doctext">
&lt;p&gt;The &lt;c&gt;{ $a cmp $b }&lt;/c&gt; comparison is the default behaviour for [doc://sort] so doesn't have to be mentioned specifically if you don't wish. You can populate your &lt;c&gt;@A&lt;/c&gt; and &lt;c&gt;@trash&lt;/c&gt; arrays in one go by eliminating the intermediate &lt;c&gt;@sorted&lt;/c&gt; array and pushing onto the appropriate array using a ternary (see [doc://perlop#Conditional-Operator]).&lt;/p&gt;
&lt;code&gt;
$ perl -Mstrict -Mwarnings -E'
&gt; my @notSorted = qw{ Beep Ape Circus Arg };
&gt; my( @A, @trash );
&gt; push @{ $_ =~ m{^A} ? \ @A : \ @trash }, $_ for sort @notSorted;
&gt; do {
&gt;    local $" = q{, };
&gt;    say qq{@A};
&gt;    say qq{@trash};
&gt;    };'
Ape, Arg
Beep, Circus
$
&lt;/code&gt;
&lt;p&gt;I hope this is helpful.&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-401112"&gt;
&lt;p&gt;Cheers,&lt;/p&gt;&lt;p&gt;JohnGG&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1001748</field>
<field name="parent_node">
1001748</field>
</data>
</node>
