Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: "foreach" is to "next" as "map" is to ???

by Belgarion (Chaplain)
on May 26, 2004 at 16:22 UTC ( [id://356627]=note: print w/replies, xml ) Need Help??


in reply to "foreach" is to "next" as "map" is to ???

Hmm, I don't think you can exclude something from inside a map, but you could place a grep before the map call. Basically, the grep would remove anything you didn't want before it's passed to the map function. So, you would have something like:

@array = map { # do stuff } grep { m/good stuff/ } @array;

This would pass anything item that matched "good stuff" to the map function for further processing.

Update After reading through the other comments posted, I guess I should not be surprised that map is more powerful than I had initially expected. I, personally, happen to think the map/grep combo is clearer code in this example, but the additional power of map is certainly nice to know.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2025-07-14 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.