in reply to PerlCritic, $_ and map
I get the same complaint, on the same line.
False positive. It apparently doesn't check for local $_. I tend to avoid local $_ anyway. What follows is a list of alternatives.
(Note that chomp is probably redundant with s/\+s$//;, so I omitted it.)
my @files = map { my $s = $_; $s =~ s/^\s+//; $s =~ s/\+s$//; $s } <$FILES>;
my @files = map { my $s = $_; for ($s) { s/^\s+//; s/\+s$//; } $s } <$FILES>;
my @files = <$FILES>; for (@files) { s/^\s+//; s/\+s$//; }
use List::MoreUtils qw( apply ); my @files = apply { s/^\s+//; s/\+s$//; } <$FILES>;
use Algorithm::Loops qw( Filter ); my @files = Filter { s/^\s+//; s/\+s$//; } <$FILES>;
Or turn off disable the critic for that instance, since you're only inadvertently modifying anonymous elements on the stack.
Do you need an array in the first place?
while (<$FILES>) { s/^\s+//; s/\+s$//; ... }
|
|---|