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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.