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

chexmix has asked for the wisdom of the Perl Monks concerning the following question:

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!