Good Day Monks,

I'm working on refactoring some scripts / code to bring it more in line with Damian Conway's _PBP_, and am using the commandline perlcritic tool to find trouble spots. One of the complaints perlcritic is spitting out (I am running it at the fairly low "stern" setting) is this:

"Don't modify $_ in list functions ..."

... and the line it is complaining about looks like this:

my @files = map {chomp;s/^\s+//; s/\+s$//; $_;} <$FILES>;

I read through the relevant material in _PBP_ & understand the drawbacks of this construction, but was fuzzy on how to best fix it. Knowing that I'd find good info at the Monastery, I went looking around. I found the following node:

http://www.perlmonks.org/?node_id=466861

And on the strength of merlyn's recommendation there, I changed the offending line to

my @files = map { local $_ = $_; chomp; s/^\s+//; s/\+s$//; $_; } <$FILES>;

Now, I did this pretty mindlessly / robotically / whatever, but I thought I understood what the rationale was for changing this in this way, so I was hopeful this edit would satisfy perlcritic.

But it didn't - I get the same complaint, on the same line. Is perlcritic in error by complaining about the _revised_ use of map, or have I done something else wrong? I admit the latter is by far the more likely ...

Thanks!


In reply to PerlCritic, $_ and map by chexmix

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.