Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
"be consistent"
 
PerlMonks  

Re: When would you choose foreach instead of map?

by Limbic~Region (Chancellor)
on May 20, 2004 at 16:56 UTC ( [id://355076]=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 When would you choose foreach instead of map?

jpfarmer,
I was confused by map for the longest time until I tried to explain it to someone else. Basically the block of a map statement is like an anonymous sub that acts on each item in the list one item at a time. Unlike a real sub, you can not specify the return value with return. The return value is the last expression evaluated. If you need to add ;$_ to get it to do the right thing, then you probably want a for loop instead. I believe when I came to this epiphany in the CB, tye had a few more good examples that I forget now.

Cheers - L~R

  • Comment on Re: When would you choose foreach instead of map?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://355076]
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.