Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re2: Idioms considered harmful

by blakem (Monsignor)
on Oct 15, 2002 at 19:00 UTC ( #205467=note: print w/replies, xml ) Need Help??


in reply to Re: Idioms considered harmful
in thread Idioms considered harmful

map { MAPCLAUSE } grep { GREPLCAUSE }
Can be rewritten as:
map { GREPCLAUSE ? MAPCLAUSE : () }
For instance, if you want a list of the squares of the first five odd numbers, either of these will work.
@odds_squared = map { $_**2 } grep { $_%2 } 1..10; @odds_squared = map { $_%2 ? $_**2 : () } 1..10; Result: 1 9 25 49 81

-Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2019-08-21 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?