The name of the rule (ProhibitMutatingListFunctions) says it already, and your use of this trim function even hides the fact that @_ is "mutated".

That means that @x will be changed after the call trim_nonempties(@x); creating a potentially buggy and hard to track side effect.

Either copy the content of @_ to a @temp array or copy the content of alias $_ within grep to a $temp scalar.

Though not sure if Critic will see that the problem was solved with the latter approach.

update

Interestingly the two aforementioned suggestions from McA and Choroba should still mutate and alarm Critic!

Please note that @x and @y aren't identical after the call, cause @x preserves empty elements.

A dual use function... Very perlish ;)

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)


In reply to Re: Code review: function to trim whitespace from all items in a list (side effect) by LanX
in thread Code review: function to trim whitespace from all items in a list by eyepopslikeamosquito

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.