Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Condensing a grep into a sort

by Roy Johnson (Monsignor)
on Jun 09, 2009 at 17:26 UTC ( #770019=note: print w/replies, xml ) Need Help??


in reply to Condensing a grep into a sort

It is not reasonable to have a sort that excludes members of the list entirely. Sort rearranges lists; grep filters them.

What you might want to do is a Schwartzian Transform so that the regex doesn't need to be applied to $a and $b repeatedly.

print map {"$_->[0]\n"} sort {$a->[1] <=> $b->[1]} map { [$_, (/C(\d*)/)[0]] } grep { /P/} @compounds;
Hoping for partial credit, I eliminated the join.

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://770019]
help
Chatterbox?
[LanX]: ?
[holli]: Re^2: Let's Make PerlMonks Great Again! -- suggestions and dreams - STFU and write code already (start already)
[LanX]: it was just after Trump-ageddon and the Americans thought I'm ridiculing them ;)
Discipulus was not the title a bit provoking? ;=)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-11-20 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (292 votes). Check out past polls.

    Notices?