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?