Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.