Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Array splitting

by Perlbotics (Canon)
on Oct 31, 2012 at 22:24 UTC ( #1001752=note: print w/ replies, xml ) Need Help??


in reply to Array splitting

TIMTOWTDI:

use strict; use warnings; my @not_sorted = qw(Ape Arg Beep Circus); my @sorted = sort {$a cmp $b} @not_sorted; my @A = grep { /^A/ } @sorted; my @trash = grep { !/^A/ } @sorted; print join(', ', @A) , "\n"; print join(', ', @trash) , "\n";

You can even include the printf(...) in the grep block, i.e. at the beginning since the result of the block should be determined by the filter expression.
Have a look at split to split an array by position. From the title of your OP, I first thought you meant that...


Comment on Re: Array splitting
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001752]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-29 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls