good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The later edition of Effective Perl Programming has item 20, "Use foreach, map and grep as appropriate", which gives an excellent summary of when to use foreach, map and grep:
Hall, McAdams and foy further caution against modifying a list via map: "For efficiency, $_ is actually an alias for the current element in the iteration. If you modify $_ within the transform expression of a map, you modify the input data. This is generally considered to be bad style, and -- who knows? -- you may even wind up confusing yourself this way. If you want to modify the contents of a list, use foreach." I'm pretty sure the earlier edition you are reading has a similar item. If you read this item, you should not be confused about which one to use. I suggest you focus on clarity and only bother benchmarking if performance is really critical. In reply to Re: Efficiency of map vs. more verbose basic/fundamental code
by eyepopslikeamosquito
|
|