Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Array splitting

by johngg (Abbot)
on Oct 31, 2012 at 22:50 UTC ( #1001758=note: print w/replies, xml ) Need Help??


in reply to Array splitting

The { $a cmp $b } comparison is the default behaviour for sort so doesn't have to be mentioned specifically if you don't wish. You can populate your @A and @trash arrays in one go by eliminating the intermediate @sorted array and pushing onto the appropriate array using a ternary (see Conditional Operator).

$ perl -Mstrict -Mwarnings -E' > my @notSorted = qw{ Beep Ape Circus Arg }; > my( @A, @trash ); > push @{ $_ =~ m{^A} ? \ @A : \ @trash }, $_ for sort @notSorted; > do { > local $" = q{, }; > say qq{@A}; > say qq{@trash}; > };' Ape, Arg Beep, Circus $

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Array splitting
by Hopfi (Novice) on Nov 01, 2012 at 00:18 UTC
    Alright. Thanks very much guys! Im more a C++ guy and not used to those different operations (like eq != ==).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001758]
help
Chatterbox?
[LanX]: eshell in emacs is often my resort in development
[LanX]: Thx found a solution! :)
[Eily]: I wrote "your" instead of "you're" :'(
[Eily]: I guess it means that my English is good enough that I make the same mistakes as native speakers though :/
[LanX]: your native tounge is French .... or Quebequois?
[erix]: never mind the natives
[Eily]: French, why?
LanX ' solution
[LanX]: lately you were talking about kids confused with "la liason"

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-03-27 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.