Truth is good; but "looks a bit clunky to me" doesn't cut much ice as a technical objection.
It was not a technical objection, I know that using map in void context works fine. I was just expressing a matter of personal taste that it may not be the best style. Others may have different opinions on that. And I was only trying to offer a possible reason why the OP asked the question in the first place.
It reflects only your own limited expectations.
Yeah, I am more limited than you, sorry about that.
Repeating cargo cult does not make it so.
Labeling others' arguments does not make the label true. Besides, this is just rhetorics, falling short of a proper intellectual argument.
map maps a function over a list; optionally returning a new list.
You are sort of rewriting the official documentation to fit your argument. The documentation says:
Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value composed of the results of each such evaluation.The map function may be used in scalar or void context, but that is definitely not its priority use. The documentation also says that map "can be used to modify the elements" of the input list, but that
Using a regular foreach loop for this purpose would be clearer in most cases.Besides concentrating on the minutia of the Perl syntax is forgetting the other bigger picture that map is used in dozens of different languages and has actually been borrowed from functional programming languages to make it possible to generate a new list from an existing one in a natural fashion. There is nothing wrong using it in a different way, but it would be wrong to deny that creating a new modified list is definitely its main purpose, which you sort of do when you write "optionally returning a new list", as if it was just a secondary possible side effect of map.
Oh, BTW, just an additional quote from the Camel Book (Programming with Style section, page 703 of the 4th edition):
Avoid using grep, map and backticks in void context; that is when you just throw away their return values. Those functions have return values, so use them. Otherwise use a foreach loop or the system function.
For the rest, I basically agree with the rest of your post and I generally have great respect for your opinions and carefully consider them, even when, as in the case in point, I don't entirely share them. And I upvoted your post despite a couple of things I don't like to much.
In reply to Re^4: Write code diferently
by Laurent_R
in thread Write code diferently
by madM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |