You can do the same inside a
map block.
foreach and
map act the same in this regard. The technical term is that the loop variable, $_ for
map and by default for
foreach, is an "alias" to the original item. Modify the alias, and you modify the original.
When would I use map? When I want to make a copy. Otherwise, I'd let other considerations take precedence. I prefer not to use map in void context, then I use foreach — as a matter of style only, there's no real technical reason to dismiss map. I use map to calculate a function value, either in scalar (count of items) or list context.