in reply to Array splitting

You need to use eq not ==,as the latter's used for numeric comparisons:

if(substr($_,0,1) eq 'A') { ...

Output:

Ape added to A Arg added to A Beep added to trash! Circus added to trash! Ape, Arg Beep, Circus

Another option is to use a regex to check the beginning character:

if(/^A/) { ...

Also, consider doing the following for your print statements:

... print "$_ added to A\n"; ... print "$_ added to trash!\n";

Replies are listed 'Best First'.
Re^2: Array splitting
by bimleshsharma (Beadle) on Nov 01, 2012 at 08:05 UTC

    here is quick solution. See if it is useful for you.

    sub split_array { my @not_sorted = qw(Ape Arg Beep Circus); my @sorted = sort {$a cmp $b} @not_sorted; my @A = (); my @trash = (); map{$_ =~/^A.*/ ? push(@A,$_):push(@trash,$_)} @sorted; print "\n",@A,"\n"; print "\n",@trash,"\n"; }